未捕获异常时会发生什么? [英] What happens when an exception is not caught?

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

问题描述

抱歉这个基本问题。我在网上发现了以下帖子

,我自己也不知道答案。

让我想起我曾经接受过关于C ++工作的电话采访。

没有帮助面试官有一个非常厚重的斯拉夫口音。他告诉我,当异常没有被抓住时会发生什么。我告诉他

程序会终止。他说那不是他要找的答案。我给了他一个详细的描述抛出

过程导致然后它到达程序的顶层并且

如果没有异常处理那里,程序终止。他说:不,我要找的是unhandledExceptionHandler

被称为 (可能没有正确的名称。)"

是否有默认的异常处理程序?

Sorry for the rudimentary question. I found the following posting
online and did not know the answer myself.
"Reminds me of a time I had a phone interview concerning a C++ job.
Didn''t help that the interviewer had a very thick Slavic accent. He
asked me what happens when an exception doesn''t get caught. I told him
the program would terminate. He said that''s not the answer he was
looking for. I gave him a kind of detailed description of the throw
process leading to "then it gets to the top level of the program and
if there is no exception handling there, the program terminates." He
said "no, what I was looking for is that the unhandledExceptionHandler
is called" (might not have the correct name.)"
Is there a default exception handler?

推荐答案

在2007-08-23 21:21,Digital Puer写道:
On 2007-08-23 21:21, Digital Puer wrote:

对于基本问题,我们深表歉意。我在网上找到了以下帖子

,我自己也不知道答案。


让我想起我有一次关于C ++工作的电话采访。

没有帮助面试官有一个非常厚重的斯拉夫口音。他告诉我,当异常没有被抓住时会发生什么。我告诉他

程序会终止。他说那不是他要找的答案。我给了他一个详细的描述抛出

过程导致然后它到达程序的顶层并且

如果没有异常处理那里,程序终止。他说:不,我要找的是unhandledExceptionHandler

被称为 (可能没有正确的名称。)"


是否有默认的异常处理程序?
Sorry for the rudimentary question. I found the following posting
online and did not know the answer myself.
"Reminds me of a time I had a phone interview concerning a C++ job.
Didn''t help that the interviewer had a very thick Slavic accent. He
asked me what happens when an exception doesn''t get caught. I told him
the program would terminate. He said that''s not the answer he was
looking for. I gave him a kind of detailed description of the throw
process leading to "then it gets to the top level of the program and
if there is no exception handling there, the program terminates." He
said "no, what I was looking for is that the unhandledExceptionHandler
is called" (might not have the correct name.)"
Is there a default exception handler?



是的,调用terminate()函数,用户可以指定一个函数

由terminate()调用,但是这个函数不允许

返回,但必须终止程序的执行。但是允许

先做一些其他的东西。


-

Erik Wikstr?m

Yes, the terminate() function is called, the user can specify a function
to be called by terminate(), however this function is not allowed to
return, but must terminate execution of the program. But it is allowed
to do some other stuff first.

--
Erik Wikstr?m


Digital Puer写道:
Digital Puer wrote:

对于基本问题,我们深表歉意。我在网上找到了以下帖子

,我自己也不知道答案。


让我想起我有一次关于C ++工作的电话采访。

没有帮助面试官有一个非常厚重的斯拉夫口音。他告诉我,当异常没有被抓住时会发生什么。我告诉他

程序会终止。他说那不是他要找的答案。我给了他一个详细的描述抛出

过程导致然后它到达程序的顶层并且

如果没有异常处理那里,程序终止。他说:不,我要找的是unhandledExceptionHandler

被称为 (可能没有正确的名称。)"


是否有默认的异常处理程序?
Sorry for the rudimentary question. I found the following posting
online and did not know the answer myself.
"Reminds me of a time I had a phone interview concerning a C++ job.
Didn''t help that the interviewer had a very thick Slavic accent. He
asked me what happens when an exception doesn''t get caught. I told him
the program would terminate. He said that''s not the answer he was
looking for. I gave him a kind of detailed description of the throw
process leading to "then it gets to the top level of the program and
if there is no exception handling there, the program terminates." He
said "no, what I was looking for is that the unhandledExceptionHandler
is called" (might not have the correct name.)"
Is there a default exception handler?



默认的未处理的异常处理程序是std :: terminate。

标准描述了在[except.terminate]

(当前版本中为15.5.1)中调用它的情况。


V

-

请在通过电子邮件回复时删除资金''A'

我这样做请勿回答最热门的回复,请不要问

The default "unhandled exception handler" is "std::terminate". The
Standard describes the cases in which it''s called in [except.terminate]
(15.5.1 in the current edition).

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


2007年8月23日星期四12:21:38 -0700,Digital Puer写道:
On Thu, 23 Aug 2007 12:21:38 -0700, Digital Puer wrote:

是否有默认的异常处理程序?
Is there a default exception handler?



或者您可以确保使用

尝试捕获任何异常{}

catch(exception_type_a a){}

catch(exception_type_b b){}

catch(exception_type_c c){}

catch(...){}


(...)表示捕获任何未被捕获的异常,这些异常在try

块中引发


否则,正如其他人所提到的,terminate()函数可以提供优惠退出程序。


or you can make sure that any exception is caught by using
try {}
catch(exception_type_a a) {}
catch(exception_type_b b) {}
catch(exception_type_c c) {}
catch(...) {}

the (...) means catch any uncaught exception that is thrown in the try
block

otherwise, as others have mentioned, the terminate() function can provide
a graceful exit from your program.


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

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