ErrorClass Conceptual Example

Top  Previous  Next

The following example shows a typical sequence of statements to declare, instantiate, initialize, use, and terminate an ErrorClass object.



    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



GlobalErrors ErrorClass                !declare GlobalErrors object



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