当我抛出异常时会发生什么? [英] What happens when I throw an exception?

查看:128
本文介绍了当我抛出异常时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些技术问题。在此函数中:

I have some technical questions. In this function:

string report() const {
    if(list.begin() == list.end()){
        throw "not good";
    }
    //do something
}

如果我扔例外情况是怎么回事?我的功能会终止还是会继续运行?如果终止,它将返回什么值?

If I throw the exception what is going on with the program? Will my function terminate or will it run further? If it terminates, what value will it return?

推荐答案

如果引发异常,则所有函数都将退回到该点在其中找到匹配类型 catch try ... catch 块。如果未从try块内调用您的函数,则程序将以未处理的异常退出。

If you throw an exception, all functions will be exited back to the point where it finds a try...catch block with a matching catch type. If your function isn't called from within a try block, the program will exit with an unhandled exception.

签出 https://isocpp.org/wiki/faq/exceptions 了解更多信息。

这篇关于当我抛出异常时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆