如果创建 com 对象失败(在我自己的类实例构造函数中),我应该抛出什么异常?例如我想创建 Excel.Application 对象。如果失败,我想抛出特定的异常,内部异常填充了 Excel.Application 构造函数生成的 COMException。
问问题
63 次
1 回答
1
如果你想创建你自己的异常类,你可以,但你不必这样做来围绕一个内部异常包装一个新的异常。
public class CustomException : Exception
{
}
public static void main()
{
try
{
//Code that instantiates COM object.
}
catch(Exception ex)
{
throw new CustomException("This is my message. I can put anything I want to, then pass the real exception as the inner exception", ex);
}
}
于 2013-10-22T12:22:56.420 回答