读书人

小白问个错误处理的有关问题

发布时间: 2013-07-09 09:50:47 作者: rapoo

小白问个异常处理的问题
code:
小白问个错误处理的有关问题

想测试除数为0的时候的异常处理,结果没有进入catch中,
而是报了Floating point exception (core dumped)错误

ps.其他类型的异常没有问题,都能被捕获并抛出......... 异常处理 异常
[解决办法]
先换成
catch(...) 试试吧
[解决办法]
Order of Handlers
Home
[解决办法]
Overview
[解决办法]
How Do I
[解决办法]
FAQ

The order in which catch handlers appear is significant, because handlers for a given try block are examined in order of their appearance. For example, it is an error to place the handler for a base class before the handler for a derived class. After a matching catch handler is found, subsequent handlers are not examined. As a result, an ellipsis catch handler must be the last handler for its try block. For example:

// ...
try
{
// ...
}
catch( ... )
{
// Handle exception here.
}
// Error: the next two handlers are never examined.
catch( const char * str )
{
cout << "Caught exception: " << str << endl;
}
catch( CExcptClass E )
{
// Handle CExcptClass exception here.
}

In this example, the ellipsis catch handler is the only handler that is examined.

读书人网 >C++

热点推荐