Default exception handling

Default exception handling must be adapted to your programming pattern.

Default program behavior when exception occurs

By default, when a language or SQL error occurs, the program stops and shows a message to the end user. However, by default, expression errors such as type conversion errors, type overflows and division by zero will not stop the program. In other words, the default is WHENEVER ERROR STOP + WHENEVER ANY ERROR CONTINUE.

In TUI mode, with default exception handlers, the error message is displayed in the terminal.

In GUI mode, with default exception handlers, the error message is displayed in a popup message box, that the user can read before the program stops. If showing detailed error messages to the end user is considered as a security risk (to prevent attacks), the original error message can be replaced by a generic error message defined in the gui.programStoppedMessage FGLPROFILE entry:
gui.programStoppedMessage = "An unexpected error occurred, program will stop."

Enforce expression error handling

By default, the WHENEVER ANY ERROR action is to CONTINUE the program flow. This means that when a program makes for example a division by zero or when a string cannot be converted to a number, the program continues. This can lead to unexpected program behavior, but is the default to be backward compatible for legacy applications.

To make your code more robust, use WHENEVER ANY ERROR STOP.

Alternatively, in case of expression errors, you can force the runtime system to execute the action defined with WHENEVER ERROR exception class, with the following FGLPROFILE entry:
fglrun.mapAnyErrorToError = true

When this entry is set to true, expression errors such as a division by zero will be trapped and execute the action defined by the last WHENEVER ERROR instruction.

When using the default exception handler (WHENEVER ERROR STOP), the program with stop at any expression error, and display the corresponding error message.


fglrun.mapAnyErrorToError = true
Program code:
  WHENEVER ERROR CALL my_error_handler 
  LET x = 1 / 0   -- error handler will be called here 
  DISPLAY "It continues...."

FUNCTION my_error_handler()
  DISPLAY "Handler: ", status