8.9.2   Exception Handling

HDevelop supports dynamic exception handling, which is comparable to the exception handling in C++ and C#.

A block of program lines is watched for run-time errors. If an error occurs, an exception is raised and an associated exception handler is called. An exception handler is just another block of program lines, which is invisible to the program flow unless an error occurs. The exception handler may directly act on the error or it may pass the associated information (i.e., the exception) on to a parent exception handler. This is also known as rethrowing an exception.

In contrast to the tracking method described in the previous section, the exception handling requires HDevelop to be set up to stop on errors. This is the default behavior. It can also be turned on explicitly:

  dev_set_check('give_error')

Furthermore, HDevelop can be configured to let the user choose whether or not an exception is thrown, or to throw exceptions automatically. This behavior is set in the preferences tab General Options ▹ Experienced User.

An HDevelop exception is a tuple containing data related to a specific error. It always contains the error code as the first item. The operator dev_get_exception_data provides access to the elements of an exception tuple.

HDevelop exception handling is applied in the following way:

  ...
  try
    * start block of watched program lines
    ...
  catch(Exception)
    * get error code
    ErrorCode := Exception[0]
    * react to error
  endtry
  * program continues normally
  ...