Exception Handling in dbx

A program stops running if an exception occurs. Exceptions signal programming
anomalies, such as division by zero or array overflow. You can set up blocks
to catch exceptions raised by expressions elsewhere in the code.

While debugging a program, dbx enables you to:

Catch unhandled exceptions before stack unwinding

Catch unexpected exceptions

Catch specific exceptions whether handled or not before stack
unwinding

Determine where a specific exception would be caught if it
occurred at a particular point in the program

If you give a step command after stopping at a point where
an exception is thrown, control is returned at the start of the first destructor
executed during stack unwinding. If you step out of a destructor
executed during stack unwinding, control is returned at the start of the next
destructor. When all destructors have been executed, a step command
brings you to the catch
block handling the throwing of the exception.

Commands for Handling Exceptions

exception [-d | +d] Command

Use the exception command to display an exception’s type at any time during
debugging. If you use the exception command without an
option, the type shown is determined by the setting of the dbx environment
variable output_dynamic_type:

If it is set to on, the derived type is
shown.

If it is set to off (the default), the
static type is shown.

Specifying the -d or +d option
overrides the setting of the environment variable:

intercept [-all] [-x] [-set] [typename] Command

You can intercept, or catch, exceptions
of a specific type before the stack has been unwound. Use the intercept command
with no arguments to list the types that are being intercepted. Use -all to intercept all exceptions. Use typename to
add a type to the intercept list. Use -x to exclude a particular
type to the excluded list to keep it from being intercepted. Use -set to
clear both the intercept list and the excluded list, and set the lists to
intercept or exclude only throws of the specified types

For example, to intercept all types except int, you
could type:

(dbx) intercept -all -x int

To intercept exceptions of type Error, you would
type:

(dbx) intercept Error

After intercepting too many CommonError exceptions,
you could exclude these exceptions by typing:

(dbx) intercept -x CommonError

Typing the intercept command with no arguments would
then show that the intercept list includes unhandled exceptions and unexpected
exceptions, which are intercepted by default, plus exceptions of class Error except for those of class CommonError.

If you then realize that Error is not the class of
exceptions that interests you, but you do not know the name of the exception
class you are looking for, you could try intercepting all exceptions except
those of class Error by typing

unintercept [-all] [-x] [typename] Command

Use the unintercept command to remove exception types from the intercept
list or the excluded list. Use the command with no arguments to list the types
that are being intercepted (same as the intercept command).
Use -all to remove all types from the intercept list. Use typename to remove a type from the intercept list. Use -x to
remove a type from the excluded list.

whocatchestypename Command

The whocatches command reports where an exception of typename would
be caught if thrown at the current point of execution. Use this command to
find out what would happen if an exception were thrown from the top frame
of the stack.

The line number, function name, and frame number of the catch clause
that would catch typename are displayed. The command
returns “typeis
unhandled” if the catch point is in the same function that
is doing the throw.

Examples of Exception Handling

This example demonstrates how exception handling is done in dbx using a sample program containing exceptions. An exception of
type int is thrown in the function bar and
is caught in the following catch block.