我有一个简单的C++代码,想要在Visual Studio 2019中编译:
#include <iostream>
#include <stdexcept>
int main()
{
std::cout << "Hello World!\n";
throw std::runtime_error{ "TEST" };
return 0;
}
在
PowerShell
中运行此程序,只会显示“Hello world”。根据我使用 GCC 的经验,我期望在终端输出中看到包含 TEST
的消息,例如:Hello World!
terminate called after throwing an instance of 'std::runtime_error'
what(): TEST
Aborted
以下是使用的编译器标志:
/permissive- /GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"Release\vc142.pdb" /Zc:inline /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /std:c++17 /FC /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\ThrowTest.pch" /diagnostics:column
如何在Windows上使用MSVC编译此程序,以显示运行时抛出的异常?
stderr
的位置,或者调用您的程序返回的错误代码是什么样的。 - qdbpTEST
? 你是在寻找调试配置吗? - zdf