自定义异常类不起作用

时间:2013-05-21 09:00:21

标签: asp.net exception-handling global-asax

为什么来自System.Exception的无效的类在try catch块中不起作用?

以下剪辑不会触发catch块

try
{
    int a = 3;
    int b = 0;
    int c = a/b;
}
catch (CustomEx er)
{    
  Console.Write(er.Message);
}

public class  CustomEx:Exception
{

}

1 个答案:

答案 0 :(得分:2)

您提供的代码无法正常运行,因为该分部会引发DivideByZeroException,并且您正在捕获CustomEx,该Exception继承自DivideByZeroException,但绝对不会来自{{1}}。

相关问题