【发布时间】:2013-12-23 02:42:47
【问题描述】:
我对声明一个在引用的 Visual C++ 程序集中定义的 Visual C++ 类型的变量时引发的 BadImageFormatException 不感兴趣,但我对异常未被捕获的事实很感兴趣try-catch 语句的 catch 子句紧接在变量声明周围,但由 try-catch 语句的 catch 子句包围对声明变量的方法的方法调用。
public static void method()
{
try
{
Some_Visual_Cpp_Type o;
}
catch (Exception)
{
Console.WriteLine("caught inside the method");//apparently not called
}
}
public static void Main()
{
try
{
method();
}
catch (BadImageFormatException)
{
Console.WriteLine("caught outside the method");//prints "caught outside the method"
}
}
有人可以解释一下这种行为吗?
【问题讨论】:
标签: c# c++ exception visual-c++