程序在异常后不会停止 [英] Program doesn't stop after exception

查看:88
本文介绍了程序在异常后不会停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu 12.04中使用eclipse。我在程序中使用了一些异常,当它们被捕获时,它将正确地提示我。但是程序继续到最后。

I am using eclipse in Ubuntu 12.04. I use some exceptions in my program and when they are caught it gives me cout correctly. But the program continues to the end. Is there a way to stop the program after exception?

这是我正在使用的代码:

This is the code I am using:

try{
        if(BLER==-1) throw 12;
    }catch(int exception){
        cout << "ERROR: BLER value is invalid for x= " << x << ", BLER_input= " << BLER_input << ", m= "<< m << endl;
    }


推荐答案

某些解决方案:


  1. 使用函数中的 return (并根据您的返回值进行操作)如果您在main()例程中执行此操作

  1. use return from your function (and do that accordingly to your return value) if you're doing this in the main() routine

使用 exit(n),其中n是退出代码( http://www.cplusplus.com/reference/cstdlib/exit/

use exit(n) where n is the exit code (http://www.cplusplus.com/reference/cstdlib/exit/)

abort()如果这是一个关键问题( http://www.cplusplus.com/reference/cstdlib/abort/

abort() if that's a critical issue (http://www.cplusplus.com/reference/cstdlib/abort/)

注意:如James Kanze, exit abort所述调用本地对象的析构函数。值得注意的是,因为您正在上课。

Notice: as noted by James Kanze, exit and abort will NOT call the destructors of your local objects. This is worth noticing since you're dealing with classes.

这篇关于程序在异常后不会停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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