【发布时间】:2011-04-16 06:50:30
【问题描述】:
try catch 和 std::runtime_error 有一个有趣的问题。 有人可以向我解释为什么这会返回“未知错误”作为输出吗? 非常感谢您帮助我!
#include "stdafx.h"
#include <iostream>
#include <stdexcept>
int magicCode()
{
throw std::runtime_error("FunnyError");
}
int funnyCatch()
{
try{
magicCode();
} catch (std::exception& e) {
throw e;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
try
{
funnyCatch();
}
catch (std::exception& e)
{
std::cout << e.what();
}
return 0;
}
【问题讨论】:
-
它使用 Visual C++ 2010 为我打印“FunnyError”。您使用的是哪个编译器?