Yes, the same approach is also in the GDB manual. Stopping at all
throw sites can be problematic, though.
Imagine you have a network application, where each layer is
implemented in its own group of functions (let's just assume A-D
layers are implemented in our web browser):
A. app. layer (web browser)
B. app. layer (HTTP client library)
C. basic reliability layer (like TCP)
D. unreliable transport (like IP)
E. ethernet, ...
Lets assume that I'm stepping through code in layer B and I'm
interested why it fails to parse certain server responses - errors are
signalled using exceptions. I have two options:
- break on exceptions off: I'm stepping over functions in B and *bam*,
suddenly the debugger loses control because of exception, all I get is
web browser (layer A) displaying "Server sent broken response"
- break on exceptions on: Now I am getting a storm of exceptions from
D (failed sends), because I am on a faulty network. However layer C
handles basic transmission errors so most exceptions do not get to B,
but I'm still seeing 5 exceptions per second that I'm not interested
in!
VS debugger solves this by stopping only when *current* stack frame
would unwind (I hope these are the correct terms, I don't have any
experience in writing debuggers). Unfortunately, VS stops on the first
line of exception handler, which is a bit late. So the best way would
be to stop when exception is thrown. Code example:
#include <cstdio>
void xyz()
{
throw 1; // D
}
void abc()
{
try {
xyz();
} catch(...) {}
throw 1; // C
}
int main()
{
try {
abc(); // A
printf("bub\n");
} catch(...) {
printf("dasd\n"); // B
}
}
When you step over the line A:
- GDB, zero: stop on D or nowhere
- VS: stops on B
- ideal debugger: stops on C