#### 5.1.3 Setting Catchpoints

You can use catchpoints to cause the debugger to stop for certain kinds of program events, such as C`++` exceptions or the loading of a shared library. Use the `catch` command to set a catchpoint.

`catch` event
  Stop when event occurs. event can be any of the following:
  `throw`
    The throwing of a C`++` exception.
  `catch`
    The catching of a C`++` exception.
  `exception`
    An Ada exception being raised. If an exception name is specified at the end of the command (eg `catch exception Program_Error`), the debugger will stop only when this specific exception is raised. Otherwise, the debugger stops execution when any Ada exception is raised.

    When inserting an exception catchpoint on a user-defined exception whose name is identical to one of the exceptions defined by the language, the fully qualified name must be used as the exception name. Otherwise, gdb will assume that it should stop on the pre-defined exception rather than the user-defined one. For instance, assuming an exception called `Constraint_Error` is defined in package `Pck`, then the command to use to catch such exceptions is `catch exception Pck.Constraint_Error`.

  `exception unhandled`
    An exception that was raised but is not handled by the program.
  `assert`
    A failed Ada assertion.
  `exec`
    A call to `exec`. This is currently only available for HP-UX and gnu/Linux.
  `fork`
    A call to `fork`. This is currently only available for HP-UX and gnu/Linux.
  `vfork`
    A call to `vfork`. This is currently only available for HP-UX and gnu/Linux.
`tcatch` event
  Set a catchpoint that is enabled only for one stop. The catchpoint is automatically deleted after the first time the event is caught.

Use the `info break` command to list the current catchpoints.

There are currently some limitations to C`++` exception handling (`catch throw` and `catch catch`) in gdb:

- If you call a function interactively, gdb normally returns control to you when the function has finished executing. If the call raises an exception, however, the call may bypass the mechanism that returns control to you and cause your program either to abort or to simply continue running until it hits a breakpoint, catches a signal that gdb is listening for, or exits. This is the case even if you set a catchpoint for the exception; catchpoints on exceptions are disabled within interactive calls.
- You cannot raise an exception interactively.
- You cannot install an exception handler interactively.

Sometimes `catch` is not the best way to debug exception handling: if you need to know exactly where an exception is raised, it is better to stop before the exception handler is called, since that way you can see the stack before any unwinding takes place. If you set a breakpoint in an exception handler instead, it may not be easy to find out where the exception was raised.

To stop just before an exception handler is called, you need some knowledge of the implementation. In the case of gnu C`++`, exceptions are raised by calling a library function named `__raise_exception` which has the following ANSI C interface:

             /* addr is where the exception identifier is stored.
                id is the exception identifier.  */
             void __raise_exception (void **addr, void *id);

To make the debugger catch all exceptions before any stack unwinding takes place, set a breakpoint on `__raise_exception` (see Breakpoints; Watchpoints; and Exceptions).

With a conditional breakpoint (see Break Conditions) that depends on the value of id, you can stop your program when a specific exception is raised. You can use multiple conditional breakpoints to stop your program when any of a number of exceptions are raised.