Navigation: ABC Library Reference > ErrorClass > ErrorClass Overview >====== ErrorClass Conceptual Example ====== | |
The following example shows a typical sequence of statements to declare, instantiate, initialize, use, and terminate an ErrorClass object.
PROGRAM
INCLUDE('ABERROR.INC') !include ErrorClass declarations
AppErrors GROUP !declare app specific errors
Number USHORT(2) !number of errors in this group
USHORT(Msg:DuplicateKey) !first error ID
BYTE(Level:Notify) !severity level
PSTRING('Duplicate Key') !window title
PSTRING('%File key is invalid.') !message text with macro
USHORT(Msg:FieldOutOfRange) !second error ID
BYTE(Level:Notify) !severity level
PSTRING('Range Error') !window title
PSTRING('%Field must be between %Message.') !message text
END
GlobalErrors ErrorClass !declare GlobalErrors object
CODE
GlobalErrors.Init !initialize (add default errors)
GlobalErrors.AddErrors(AppErrors) !add app specific errors
GlobalErrors.SetFatality(Msg:DuplicateKey,Level:Fatal)!modify severity of an error
!
!program code
!
!user attempts to enter invalid month value
GlobalErrors.SetField('Month') !set %Field for macro expansion
GlobalErrors.ThrowMessage(Msg:FieldOutOfRange,'1 and 12') !pass error to errormanager
!
!user attempts to insert a duplicate key…
GlobalErrors.SetFile('Customer') !set %File for macro expansion
GlobalErrors.Throw(Msg:DuplicateKey) !pass error to errormanager
!program code
!
GlobalErrors.Kill !shut down GlobalErrors object