admin管理员组文章数量:1399013
I've encountered weird behavior of debugger on Windows (MSVC17), which I managed to replicate with code as simple as
#include <iostream>
int main()
{
throw std::exception();
std::cout << "Hello World!" << std::endl;
return 0;
}
When I execute the code without the debugger attached, it behaves as expected - unhandled exception terminates program.
However, when I execute it with the debugger attached, something weird happens:
This correctly reports Unhandled exception at 0x00007FFCCBB8FE3C in ConsoleApplication1.exe: Microsoft C++ exception: std::exception at memory location 0x000000753FAFFB08.
But when I press Continue, the code continues as if the exception wasn't there:
I've also tried this code on Linux with GDB, which terminated application as expected.
After some research I've found this post, which says that it is correct behavior of MSVC debugger, but then I would expect this code to behave the same:
#include <iostream>
int main()
{
try
{
throw std::exception();
}
catch (...)
{
throw;
}
std::cout << "Hello World!" << std::endl;
return 0;
}
This code correctly catches the first exception and rethrows it, but when rethrowing, I would expect debugger to ignore the exception as for the first time. It correctly reports Unhandled exception at 0x00007FFCCBB8FE3C in ConsoleApplication1.exe: Microsoft C++ exception: std::exception at memory location 0x00000056D930F9F8.
, but when continued in debugger, I get access violation (Exception thrown at 0x0000000000000000 in ConsoleApplication1.exe: 0xC0000005: Access violation executing location 0x0000000000000000.
) and the debugger gets stuck there.
Why is debugger skipping unhandled exceptions and don't terminate the program? If it is correct behavior, why it doesn't work in second case? Am I able to turn this "feature" off?
Thank you for your help!
// Edit: Adding compiler flags
/JMC /permissive- /ifcOutput "ConsoleA.5d991025\x64\Debug\" /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"ConsoleA.5d991025\x64\Debug\vc143.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /FC /Fa"ConsoleA.5d991025\x64\Debug\" /EHsc /nologo /Fo"ConsoleA.5d991025\x64\Debug\" /Fp"ConsoleA.5d991025\x64\Debug\ConsoleApplication1.pch" /diagnostics:column
本文标签: cUnhandled exception termination ignored while debugger is attachedStack Overflow
版权声明:本文标题:c++ - Unhandled exception termination ignored while debugger is attached - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744105931a2591063.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论