如何获取有关异常的信息? [英] How do I get information about an exception?

查看:81
本文介绍了如何获取有关异常的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下语法来捕获使用Visual C ++ 1.0的异常:



I'm using the following syntax to catch exceptions using Visual C++ 1.0:

TRY
{
   //Some code
} 
CATCH(CException, e)
{                                   
  //Get info about error here?  Members of variable e?		
}
END_CATCH





我希望获得有关异常的更多信息。我能这样做吗?如果是的话,请问怎么样?





问候,

Mike



I'd like to get more information about the exception when it is caught. Can I do that? If so, then how, please?


Regards,
Mike

推荐答案

您拥有的对象 c 可以随身携带,不多也不少。



分辨率在投掷方面。您可能需要抛出自己的异常类型的对象,因此请确保它们足够的信息。通常,此类自定义异常仅添加有关环境的信息。例如,您将与整数除法相关的异常捕获为零。您可以捕获此异常并重新抛出它,但不能使用相同的类型。你可以拥有自己的异常类型,用于解释环境,为什么发生这种划分,在什么语义操作中,抛出异常,而不是原始的低级异常。这是结构异常处理的目的之一。另一个最重要的是将常规代码与特殊代码隔离开来。实际上,你不应该在本地处理异常。



-SA
You have as much information as the object c can carry, no more, not less.

The resolution is on the throwing side. You may need to throw you own objects of your own exception types, so make sure they are informative enough. Often, such custom exceptions add just information on the environment. For example, you catch the exception related to integer division by zero. You can catch this exception and re-throw it, but not of the same type. You can have your own exception type designed to explain the circumstances, why that division happened, in what semantic operation, and throw that exception, instead of original "low-level" exception. This is one of the purposes of structural exception handling. Another, most important one is isolation of "regular" code from exceptional. Practically, you should not handle exception too locally.

—SA


这篇关于如何获取有关异常的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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