我使用MinGW的GCC(或g ++)7.1.0在Windows 10为什么重新抛出异常会丢弃'what()'给出的信息?
通常,抛出std::runtime_error
示出了这样的信息:
terminate called after throwing an instance of 'std::runtime_error'
what(): MESSAGE
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
但下面的代码仅示出了最后两行和what()
信息丢失:
#include <stdexcept>
using namespace std;
int main() {
try {
throw runtime_error("MESSAGE");
} catch (...) {
throw;
}
}
所以以上仅输出的代码:
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
如果我用const exception&
,const runtime_error&
(或没有const
,没有&
,或没有这两个)替换...
,会发生同样的情况。
据我所知,throw;
重新抛出当前捕获的异常。那为什么不显示what()
?
是什么让你认为重新抛出异常丢弃通过“什么()”中给出的信息?你再也不检查什么()会在重新抛出后返回。显示“此应用程序已请求”消息,因为您未捕获异常导致的程序被终止。 '什么()'不应该被打印。 – VTT
怪Windows。 http://ideone.com/UVRna0 –
@VTT也许这是关于重新说明的东西......我知道异常对象中的信息是IS,并且手动输出信息确实有效,但是如果'what()自动显示像正常? – TRCYX