Debugging C++ Applications Using HP WDB (766162-001, March 2014)

catch-points which can cause the debugger to stop for C++ Exceptions. You can use any of the
following commands to catch C++ exceptions:
DescriptionCommand
WDB stops program when any C++ exception is thrown.catch
throw
WDB stops program when any C++ exception is caught.catch
catch
Use the following command to display the exceptions that can be caught.
info catch [ all | *<ADDR> | [<FILE>:]<LINE>]
Use info catch for the selected frame.
Use info catch all to list all the exceptions that can be caught.
Use info catch *address or info catch file:line to list catches for a particular
instruction.
Example 16 shows a sample program for debugging with exceptions.
Example 16 Sample Program for Debugging Exceptions
1 #include <iostream>
2 using namespace std;
3
4 class E {
5 public:
6 const char* error;
7 E(const char* arg) : error(arg) { }
8 };
9
10 void g() {
11 throw E("Exception thrown in g()");
12 }
13
14 int main() {
15
16 try { // Try block
17 g();
18 }
19 catch (E& e) { // Catch block
20 cout << e.error << endl;
21 }
22 return 0;
23 }
The WDB output snippet for this program is as shown below:
(gdb) b main
Breakpoint 1 at 0x4001ae0:1: file exception.C, line 17 from /exception.
(gdb) r
Starting program: /exception
Breakpoint 1, main () at exception.C:17
17 g();
(gdb) info catch all
Catch locations are at ...
exception.C:19 catch(class E &) in main()
(gdb) catch throw
Catchpoint 2 (throw)
(gdb) catch catch
Catchpoint 3 (catch)
(gdb) info breakpoints
Num Type Disp Enb Address What
Catching C++ exceptions 27