未捕获的异常会发生什么 [英] what happens with uncaught exception

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

问题描述

好奇。想象一下,我的应用程序抛出一些异常,例如,抛出错误;

- 如果没有在任何地方捕获,这将导致崩溃最后对吗?

Hi, just curious. Imagine my app throws some exception, e.g., throw "error";
-- if this is not caught anywhere, this will result in a crash in the end right?

推荐答案

是的,你的程序会崩溃,但它究竟会如何运行取决于几件事。

你是在编写C ++但是在什么操作系统和什么框架上?



例如在Windows上,一些框架会为你安装一个未处理的异常过滤器,有些则不会。

回到那天我不认为MFC做了,但现在可能。这意味着你会得到一个崩溃对话框,说明你有一个未处理的异常,甚至可能让用户有机会尝试继续执行,这通常是一个坏主意。否则,框架可能会让用户有机会在此时向开发人员报告崩溃,这可能是一个好主意。

在大多数情况下,您当然可以安装自己的未处理的异常过滤器来覆盖任何提供的为了你。但是,在所有情况下,您都需要确定会发生什么,以便保护用户数据。一如既往的建议是了解你的敌人。 : - )
Yes your program will crash but exactly how it will go out depends on a couple of things.
You're writing C++ but on what OS and with what framework?

For example on Windows some frameworks will install an unhandled exception filter for you and some won't.
Back in the day I don't think MFC did but now it may. This means you'll get a crash dialog that says you had an unhandled exception and may even give the user the opportunity to attempt to continue execution which is generally a bad idea. Otherwise the framework may give the user the opportunity to report the crash to the developer at this point which is possibly a good idea.
In most cases you can of course install your own unhandled exception filter overriding any provided for you. In all cases however you need to be sure of what will happen so you can protect the users data. The advice as ever is to know your enemy. :-)


如果你没有捕获异常,那么它甚至会解开程序的main()/ WinMain()调用,并且异常会被运行时库捕获不能导致幸福的结局。
If you don't catch the exception then it is unwinds even the main()/WinMain() call of your program and the exception gets caught by the runtime library that simply can not result in a happy end.


是的,因为您可能很容易验证自己。
Yes, as you might easily verify yourself.


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

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