Error System¶
Include: Use System\ErrorSystem.pkg
The Error System routes runtime errors to an error handler. Local Try/Catch blocks let code handle a reported error around a protected block, while the Error command creates and reports an error through the Error System.
Topics¶
- Try/Catch - Handles errors reported while a protected block runs.
Handler¶
- cBaseErrorHandler - Base error handler class.
Globals¶
- Error - Signals an error to the Error System.
- UserError - Raises a user-facing error.
- Error numbers - Grouped
DFERR_*constants.
Try/Catch and Error¶
| Construct | Use it when | What it does |
|---|---|---|
| Try/Catch | Code can recover from, translate, clean up after, or re-raise an error from a block. | Runs protected code and transfers control to Catch if an error is reported inside the block. |
Error |
Code detects an invalid condition and needs to report it as an Error System error. | Raises/reports the supplied error number and optional text through the Error System. |
Try/Catch does not create an error by itself; it handles an error raised by runtime code, package code, or an explicit Error command.
Error does not recover from anything; it reports the error, so use it at the point where the invalid condition is detected.
A Catch block may handle the error locally or re-raise/report an error again when callers still need to see it. For example, transaction commands clean up and use Error Last_Error_Number ErrText so the caller's error handler still sees the error.
For the full protected-block flow and Catch variable forms, see Try/Catch.
Example¶
Procedure SaveCustomer String sCustomerName
Try
If (sCustomerName = "") Begin
Error DFERR_OPERATOR "Customer name is required."
End
Send DoSaveCustomer sCustomerName
Catch
Send UserError ErrText "Save failed"
End_Try
End_Procedure
The Error command reports the invalid empty name; Catch handles any error from the guarded block and converts it to a user-facing message.