When debugging a console app, Visual Studio gets stuck in an exception-reporting loop. Why?

后端 未结 4 1383
野趣味
野趣味 2021-01-21 04:08

Consider this simple console application:

using System;

namespace Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            t         


        
相关标签:
4条回答
  • 2021-01-21 04:50

    The VS2012 debugger won't continue past an unhandled exception

    0 讨论(0)
  • 2021-01-21 04:51

    It doesn't do that. If the application wasn't running in the debugger, you'd get an "application quit unexpectedly" dialog - but not in Visual Studio.

    While I'm not exactly sure why it behaves like that, it may be because it gives you the option to move the "currently executing line" arrow (the yellow array) to the next line that should be executed and to resume operation.

    Otherwise, yes, you need to stop the application explicitly.

    0 讨论(0)
  • 2021-01-21 04:54

    By default, the debugger stops on all exceptions, that are not caught (i.e. unhandled) - this can be changed in the Exceptions dialog (CTRL+ALT+E, with my keybindings)

    0 讨论(0)
  • 2021-01-21 04:59

    What did you expect?

    Consider the following method:

    private void Test()
    {
        throw new Exception();  
        int u = 4;
    }
    

    When the exception is thrown, the debugger allows you to navigate to the calling context to see if your program catches the exception. If it's not the case, it never exits the Test method by skipping the exception, that's why int u = 4; is unreachable.

    In your example, it's the same:

    private static void Main(string[] args)
    {
        throw new Exception();
    
        // If I'm here, I will exit the application !
        // But this place is unreachable
    }
    

    You can't exit the Main method scope because of your exception. That's why you can't exit your application while debugging using F5.

    If you have no debugger attached, your application will of course crash because of an unhandled exception, but this is another story.

    0 讨论(0)
提交回复
热议问题