【发布时间】:2020-04-04 03:51:28
【问题描述】:
在调试我的代码时,gdb 会捕获常规异常(例如除以零),但不会捕获自定义异常,并使用 throw 抛出。
我希望 vscode 会跳转到引发异常的位置,因此我可以进行调查。相反,该异常会导致应用程序终止并关闭调试器。
我用一些虚拟代码对其进行了测试:
编译为: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;
}
输出:
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.
我的环境:
- Windows 7 64 位
- VSCode 1.40.2
- MinGW
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
}
【问题讨论】:
-
有一个解决方法。我可以在抛出异常的地方放置一个断点,然后进行调查。
-
请接受。
-
@OwnageIsMagic 抱歉,我没有看到这个问题,因为我最后的解决方法是将 C++ 开发切换到 Linux。
标签: c++ windows visual-studio-code windows-7 gdb