忽略C#命令行程序中的try块

Lan*_*her 3 c# console command-line visual-studio-2008

我在C#中有一个命令行程序,我用一个try-catch块包装,以防止它崩溃控制台.但是,当我调试它时,如果在DoStuff()方法的某处抛出异常,Visual Studio将在"catch"语句中中断.我希望Visual Studio能够打破异常发生的位置.最好的方法是什么?

评论试试?
Visual Sudio中的一个设置?
#if DEBUG语句?

static void Main(string[] args)
{
    try
    {
        DoStuff();
    }
    catch (Exception e)
    {  //right now I have a breakpoint here
        Console.WriteLine(e.Message);
    }
}

private void DoStuff()
{
    //I'd like VS to break here if an exception is thrown here.
}
Run Code Online (Sandbox Code Playgroud)

Pau*_*rst 8

你可以在VS中启用First chance exception.这将允许您在引发异常时立即得到通知.