Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleException View Entity
linenumberstrue
---------------------------------------------------------------------------------------------
-- 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;

...

Code Block
titleExpress Helper functions and procedures
linenumberstrue
collapsetrue
------- Create an new innermost exception representing the current xpxExceptionId object
Function GetEDMException : Aggregate Of Exception; 
   GExceptions := [];
   CreateEDMException;
   Return(GExceptions);
End_Function;

Procedure NewEDMException;
   GExceptions := [];
   CreateEDMException;
End_Procedure;

-- Create an new "selfmade" innermost exception -------------------------------------------------------------------------
-- 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
GExceptions   := [];  lInnerException : NewOuterException(Message)Exception;
   Return(GExceptions);
End_FunctionLocal;
   ProcedureIf NewException(Message : String);
   GExceptions := [];NVL(xpxExceptionId.errCode, 0) <> 0 Then
   NewOuterException(Message); End_Procedure;  -- CreateEDM anerror
new outer exception on the previous (inner) exception 
Function GetOuterException(Message : String) : Aggregate Of ExceptionlInnerException := GException;
      New GException;
    NewOuterException(Message);  GException._Type_  Return(GExceptions); End_Function;  Procedure NewOuterException(Message := String)'edmException';
   Local   GException.errCode    lInnerException  := ExceptionxpxExceptionId.errCode;
    End_Local;  GException.errMessage  lInnerException := GException;xpfGetErrorText(xpxExceptionId.errCode);
     New GException.functionName := xpxExceptionId.functionName;
      GException._Type_ lineNumber   := xpxExceptionId.lineNumber;
      GException.innerException := 'xpxException'lInnerException;
   GException.userMessage    := Message;
   GException.innerException := lInnerException;   xpxPrintf('Line #%d: Exception. EDM Error number: %d, Message: %s', xpxCurrentLine, GException.errCode, GException.errMessage);
      GExceptions ++ GException;
   End_ProcedureIf;
 Procedure CreateEDMException; If NVL(Message,  Local'') <> '' Then
      lInnerException := ExceptionGException;
   End_Local;   New lInnerException := GException;

  New GException;    GException._Type_         := 'edmExceptionxpxException';
      GException.errCodeuserMessage    := Message;
      GException.innerException := xpxExceptionId.errCodelInnerException;
     GException.errMessage   := xpxExceptionId.errMessage;
   GException.functionName := xpxExceptionId.functionName;
   GException.lineNumber   := xpxExceptionId.lineNumber;
   GException.innerException := lInnerException;
   GExceptions ++ GException;
End_procedure; 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

Code Block
languagevb
title.Net VB Example
linenumberstrue
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

...