当我声明一个在引用的Visual C++程序集中定义的Visual C++类型的变量时,我不会被引发的BadImageFormatException所吸引,因为我对这个异常未被catch子句捕获这一事实感到好奇.紧接着变量声明的try-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" } }
有人可以解释一下这种行为吗?
当方法为JIT时,在其catch块存在之前抛出此异常.