public class Entry
{
public void Main()
{
var p = new Class1();
}
}
public class Class1
{
public Class1()
{
DoSomething();
}
private void DoSomething()
{
try
{
CallToMethodWhichThrowsAnyException()
}
catch (Exception ex)
{
throw new CustomException(ex.Message); // where CustomException is simple System.Exception inherited class
}
}
}
为什么我CustomException不会抛出和Entry.Main或Class 1的构造停止调试的执行(或在我的DoSomething方法中)?
立即窗口中只有消息A first chance exception of type 'MyLibrary.CustomException' occurred in MyLibrary.dll
。
Visual Studio的异常设置被设置为所有CLR异常仅在用户未处理时抛出。
'CallToMethodWhichThrowsAnyException'已经在处理'NullReferenceException' – 2013-03-14 13:26:17
是的,但是在catch块中我抛出了一个新的异常,我期待着我的程序在任何时候都会崩溃。但是这个例外只是“吞噬”,而执行将继续。 – 2013-03-14 13:27:34
很难分辨您发布的内容。在实例化Class1的行上放置一个断点,然后遍历代码。它在做你认为会怎么样的事情吗? – 2013-03-14 13:27:34