【发布时间】:2015-06-26 09:44:12
【问题描述】:
我正在尝试使用异常打印类型名称,但我的程序似乎甚至没有捕获异常,而是似乎调用了默认终止函数。我错过了什么?
#include <cstdio>
#include <exception>
#include <typeinfo>
namespace Error
{
template<typename T>
class Blah : std::exception
{
virtual const char* what() const throw()
{
return typeid(T).name();
}
};
}
void blah() {
throw Error::Blah<int*********>();
}
int main()
{
try
{
blah();
}
catch (std::exception& e)
{
std::puts(e.what());
}
}
【问题讨论】:
标签: c++ exception inheritance