I have a C++ application which terminates with a "bad allocation" error message for certain input data on an AIX machine.
Is there a way to run the program in dbx and catch the exception when it's being thrown? I don't see anything about it in IBM's documentation.
If your C++ application is compiled with XL C/C++, set a breakpoint on __DoThrowV6.
$ cat throw.C
int foo(int x)
{
if (x < 0)
throw 99;
return x+1;
}
int main()
{
int y;
y = -5;
try
{
foo(y);
}
catch(...)
{
}
return 0;
}
$ xlC -g -o throw throw.C
$ dbx ./throw
Type 'help' for help.
reading symbolic information ...
(dbx) stop in __DoThrowV6
[1] stop in __DoThrowV6
(dbx) run
[1] stopped in __DoThrowV6 at 0xd1be7e00
0xd1be7e00 (__DoThrowV6) 7c0802a6 mflr r0
(dbx) where
__DoThrowV6() at 0xd1be7e00
foo(int)(x = -5), line 4 in "throw.C"
main(), line 14 in "throw.C"
(dbx)
__DoThrowV6 is called when an exception is thrown, so from the call stack one can see that the exception was thrown from line 4 of the source file throw.C