Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

There is now a way to throw an exception in the edmiNET binding's Execute function of the query object from the xpx machine. Works on externally callable query functions that has generic return type (generic or aggregate of generic). To raise an .NET xpxException in edmiNET you need to create a view_entity like this and return it in an aggregate:

Exception View Entity
---------------------------------------------------------------------------------------------
-- Exception handling
-- In the global section declare the following:
-- GLOBAL
--    GExceptions                : Aggregate Of Exception := [];
--    GException                 : Exception;
--    ...
-- END_GLOBAL;


VIEW_ENTITY Exception;
   _Type_       : STRING;  -- Either 'edmException' or 'xpxException'
   errCode      : INTEGER; -- EDM error code as returned from xpxExceptionId
   errMessage   : STRING;  -- EDM error message as returned from xpxExceptionId
   userCode     : INTEGER; -- Selfmade code
   userMessage  : STRING;  -- Selfmade message
   functionName : STRING;  -- Function as returned from xpxExceptionId or selfmade
   lineNumber   : INTEGER; -- Line number as returned from xpxExceptionId or selfmade.
   innerException : Exception;
END_VIEW_ENTITY;

The individual exception data is available in the xpxException object.

Express Helper functions and procedures
--------------------------------------------------------------------------------
-- Declare in beginning of every function to ensure that all EDM errors are 
-- caught and that exceptions propagate upwords in the stack.
--    On_Error_Do xpxThrow(GetException(?)); End_On_Error_Do;
-- Throw "soft" errors from code like this:
--    xpxThrow(GetException('Something when wrong'));
-- To ignore an exception and reset exception chain:
--    On_Error_Do cancelException; End_On_Error_Do;
Function GetException(Message : String) : Aggregate Of Exception;
   Local
      lInnerException : Exception;
   End_Local;
   If NVL(xpxExceptionId.errCode, 0) <> 0 Then
      -- EDM error
      lInnerException := GException;
      New GException;
      GException._Type_       := 'edmException';
      GException.errCode      := xpxExceptionId.errCode;
      GException.errMessage   := xpfGetErrorText(xpxExceptionId.errCode);
      GException.functionName := xpxExceptionId.functionName;
      GException.lineNumber   := xpxExceptionId.lineNumber;
      GException.innerException := lInnerException;
      xpxPrintf('Line #%d: Exception. EDM Error number: %d, Message: %s', xpxCurrentLine, GException.errCode, GException.errMessage);
      GExceptions ++ GException;
   End_If;
   If NVL(Message, '') <> '' Then
      lInnerException := GException;
      New GException;
      GException._Type_         := 'xpxException';
      GException.userMessage    := Message;
      GException.innerException := lInnerException;
      xpxPrintf('Line #%d: Exception: Message: %s', xpxCurrentLine, GException.userMessage);
      GExceptions ++ GException;
   End_If;
   Return(GExceptions);
End_Function;

-- To ignore an exception from lower level and continue 
-- execution as normal call the following function.
Procedure CancelException;
   GExceptions := [];
   GException := ?;
End_Procedure;
---------------------------------------------------------------------------------------------

edmiNet

.Net VB Example
Try
   EnterpriseModel.NewQuery.Execute("CatDictionaryServices", "UpdateExchangeRequirementConceptAttribute", New Object() {New Instance(ProductPage.ERConceptId),
                                                                                                                                     New Instance(lGroupId),
                                                                                                                                     New Instance(lConceptId),
                                                                                                                                     Column.Name, NewValue})
    RefreshRow = True
Catch XPXEx As XPXException
    XtraMessageBox.Show(XPXEx.Message)
Catch Ex As Exception
    XtraMessageBox.Show(Ex.ToString)
End Try
.NET C# Example
try {
		EnterpriseModel.NewQuery.Execute("CatDictionaryServices", "UpdateExchangeRequirementConceptAttribute", new object[] {
			new Instance(ProductPage.ERConceptId),
			new Instance(lGroupId),
			new Instance(lConceptId),
			Column.Name,
			NewValue
		});
		RefreshRow = true;
} catch (XPXException XPXEx) {
		XtraMessageBox.Show(XPXEx.Message);
} catch (Exception Ex) {
		XtraMessageBox.Show(Ex.ToString);
}

If there is a usermessage in the xpxException object this will be shown as the Message of the exception object. If there is no usermessage and there is a edmErrroCode the message will look like this:

Example output
Error number 11298: Illegal data type or data value of argument #1.
Function: xpfGetInstanceModel
Line number: 1581
Query function: CatDictionaryServices.UpdateExchangeRequirementConceptAttribute

 

 

  • No labels