意外异常处理程序 [英] unexpected exception handler

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

问题描述

大家好,


这个问题是关于什么时候允许调用throw来重新抛出异常 - 让异常重新抛出。


我只能想到两种情况,


1.在异常的阻止区块中;

2.意外处理器。


对于(2),在意外的处理程序中,由于输入参数为null,所以为了获取异常信息,我们需要重新抛出它并将其捕获到得到异常信息。


我的理解是否正确?这是Bjarne的书中的一些伪代码。

Hello everyone,


This question is about when it is allowed to call throw to re-throw exception -- make the exception re-throw.

I can only think of two situations,

1. in catch block of an exception;
2. in unexpected handler.

For (2), in unexpected handler, since the input parameter is null, so in order to get the exception information, we need to re-throw it and catch it to get exception informaiton.

Is my understanding correct? Here is some pseudo code from Bjarne''s book.

展开 | 选择 | Wrap | 行号

推荐答案

您的例子不是重新抛出。它显示的是捕获异常A并抛出异常B.


通常在捕获的异常不是要报告的错误时执行。也就是说,内存异常在低级别可能没问题,但在用户级别你可能需要更通用的东西。


这是一次重新抛出:
Your example is not a re-throw. What it shows is catching exception A and throwing exception B.

This is commonly done when the caught exception is not the corrrect one to report. That is, a memory exception may be OK at a low level but at a user level you may need something more general.

This is a re-throw:
展开 | 选择 | Wrap | 行号


Hi weaknessforcats,


我的问题是解决你在下面提到的问题 - 抛出意外异常以及如何检索异常信息。


我不确定我的代码和我的理解是否正确,因此我让人们在这里进行审核和评论。 :-)


你跟我提到的一样吗?

Hi weaknessforcats,


My question is to solve the issue you mention below -- unexpected exception is thrown and how to retrieve exception information.

I am not sure whether my code and my understanding is correct, and so I let people here to review and comment. :-)

Do you agee what I mentioned?


但是,关于原始异常的信息无法收回。这样做是为了通过抛出预期的异常来拯救你的程序从死亡的下颚(没有返回的意外处理程序)。
However, the information on the original exception cannot be retreived. This sort of this is done to rescue your program from the jaws of death (the unexpected handler from which there is no return) by throwing an expected exception.



问候,

George


regards,
George



我的问题是要解决你在下面提到的问题 - 抛出意外异常以及如何检索异常信息。
My question is to solve the issue you mention below -- unexpected exception is thrown and how to retrieve exception information.



也许我不清楚。如果您不知道异常的类型,那么以后就无法恢复异常信息。也就是说,如果它出乎意料的话你最终会遇到意外的()处理程序,因为没有参数也没有返回。

Maybe I wasn''t clear. If you don''t know the type of the exception , then there''s no recovery of the exception information later. That is, if it''s unexpected you just end up in the unexpected() handler whioch ahs no arguments and no return.


这篇关于意外异常处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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