Reputation: 666
While debugging my code, gdb catches regular exceptions (such as dividing by zero) but not custom ones, thrown with throw
.
I'd expect vscode to jump where the exception is thrown, so i can investigate. Instead, the exception causes the application to terminate and the debugger to close.
I tested it with some dummy code:
compiled with: g++ -g main.cpp -o test.exe
#include <stdexcept>
#include <iostream>
void test()
{
throw std::invalid_argument( "received negative value" );
}
int main(int argc, char const *argv[]) {
std::cin.get();
// int c = 1 / 0;
test();
std::cout << "v";
std::cin.get();
return 0;
}
The output:
terminate called after throwing an instance of 'std::invalid_argument'
what(): received negative value
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
My environment:
launch.json
{
"type": "cppdbg",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/test.exe",
"cwd": "${workspaceRoot}",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"MIMode": "gdb",
"preLaunchTask": "Compile",
"externalConsole": true
}
Upvotes: 7
Views: 6548
Reputation: 2299
For more info about catch
see https://sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints.html#Set-Catchpoints
add to launch.json
:
{
...
"setupCommands": [
/*{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},*/
{
"description": "Enable break on all exceptions",
"text": "catch throw",
"ignoreFailures": true
}
],
...
}
Upvotes: 12