【发布时间】:2019-11-14 07:04:51
【问题描述】:
我有一个简单的 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被重定向到使用 powershell 或通过调用您的程序返回的错误代码的情况.. -
我不知道 GCC,但是为什么 VC 会显示
TEST?您在寻找调试配置吗?
标签: c++ exception visual-c++ compilation