Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. C# Recipe for uncatchable exception

C# Recipe for uncatchable exception

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdebugginghelpvisual-studiocom
32 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Super Lloyd

    I had the following code in my app. Turns out you just CAN'T debug that code. At least with Visual Studio 2017, It will crash your process instantly and you will be left without any clue as to what was wrong!! Gotta report that to Microsoft.. Meanwhile, behold the evilest safe C# code that can be!

    class Program
    {
        static void Main(string\[\] args)
        {
            try { Fail(); }
            catch (Exception ex) { Log(ex); }
        }
        static void Fail()
        {
            throw new NotSupportedException("You Fool!");
        }
        static void Log(Exception ex)
        {
            var sb = new StringBuilder();
            Log(ex);
            Console.WriteLine($"Problem: {sb}");
        }
    }
    

    [EDIT] To clarify, of course this code is buggy, it's a bug repro. But most remarkably the program just crash without hint from Visual Studio. Even if you ask Visual Studio to stop on StackOverflowException, it won't! [EDIT2] Setting breakpoints is not the problem... But why would you put a breakpoint there if you didn't know the bug was there in the first place? FYI it's about 1 month of work before this bug came to light!

    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

    Kornfeld Eliyahu PeterK Offline
    Kornfeld Eliyahu PeterK Offline
    Kornfeld Eliyahu Peter
    wrote on last edited by
    #7

    I had no problem at all to set breakpoints and debug the code - no crash of VS... Actually the code has that logical problem of infinite recursion, but VS just stops after the application comes to a 0x800703e9 (COR_E_STACKOVERFLOW) error... which in my cases happening after 11708 iterations...

    Quote:

    The program '[19424] ConsoleApp2.exe' has exited with code -2147023895 (0x800703e9).

    StackOverflowException Class (System)[^] When can you catch a StackOverflowException? – jaredpar's WebLog[^]

    "The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge". Stephen Hawking, 1942- 2018

    "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

    S 2 Replies Last reply
    0
    • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

      I had no problem at all to set breakpoints and debug the code - no crash of VS... Actually the code has that logical problem of infinite recursion, but VS just stops after the application comes to a 0x800703e9 (COR_E_STACKOVERFLOW) error... which in my cases happening after 11708 iterations...

      Quote:

      The program '[19424] ConsoleApp2.exe' has exited with code -2147023895 (0x800703e9).

      StackOverflowException Class (System)[^] When can you catch a StackOverflowException? – jaredpar's WebLog[^]

      "The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge". Stephen Hawking, 1942- 2018

      S Offline
      S Offline
      Super Lloyd
      wrote on last edited by
      #8

      Breakpoint is not a problem.. But why would you put a breakpoint there if you didn't know the bug was there in the first place? That was my problem! Only 600 files changed... Had to the find the wrong change.... Didn't have the insight to put the breakpoint in the right spot right away! Now, now, I wonder, how come it was so hard for you to understand that? I think I might not have make myself very clear.. not sure though how to improve my communication though... Any tips?

      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

      Kornfeld Eliyahu PeterK L 2 Replies Last reply
      0
      • S Super Lloyd

        Breakpoint is not a problem.. But why would you put a breakpoint there if you didn't know the bug was there in the first place? That was my problem! Only 600 files changed... Had to the find the wrong change.... Didn't have the insight to put the breakpoint in the right spot right away! Now, now, I wonder, how come it was so hard for you to understand that? I think I might not have make myself very clear.. not sure though how to improve my communication though... Any tips?

        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

        Kornfeld Eliyahu PeterK Offline
        Kornfeld Eliyahu PeterK Offline
        Kornfeld Eliyahu Peter
        wrote on last edited by
        #9

        It is true. Even knowing that there was a overflow exception does not help, as VS does not tell where and it is uncatchable...

        "The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge". Stephen Hawking, 1942- 2018

        "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

        1 Reply Last reply
        0
        • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

          I had no problem at all to set breakpoints and debug the code - no crash of VS... Actually the code has that logical problem of infinite recursion, but VS just stops after the application comes to a 0x800703e9 (COR_E_STACKOVERFLOW) error... which in my cases happening after 11708 iterations...

          Quote:

          The program '[19424] ConsoleApp2.exe' has exited with code -2147023895 (0x800703e9).

          StackOverflowException Class (System)[^] When can you catch a StackOverflowException? – jaredpar's WebLog[^]

          "The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge". Stephen Hawking, 1942- 2018

          S Offline
          S Offline
          Super Lloyd
          wrote on last edited by
          #10

          This document is outdated. If you cause a stack overflow yourself (outside a catch block) (not throwing the exception mind you, but real unbounded recursion) VS will stop and show you the stack. Many a times it helped me in the recent past! ;) Otherwise yeah, one could never catch and terminate such an exception. I knew that too. Doesn't help though! ;P

          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

          1 Reply Last reply
          0
          • P Pete OHanlon

            It's exceptions all the way down.

            This space for rent

            S Offline
            S Offline
            Super Lloyd
            wrote on last edited by
            #11

            Boom! :laugh:

            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

            1 Reply Last reply
            0
            • S Super Lloyd

              Breakpoint is not a problem.. But why would you put a breakpoint there if you didn't know the bug was there in the first place? That was my problem! Only 600 files changed... Had to the find the wrong change.... Didn't have the insight to put the breakpoint in the right spot right away! Now, now, I wonder, how come it was so hard for you to understand that? I think I might not have make myself very clear.. not sure though how to improve my communication though... Any tips?

              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #12

              Super Lloyd wrote:

              That was my problem! Only 600 files changed...

              All of them using recursion? :)

              Super Lloyd wrote:

              Didn't have the insight to put the breakpoint in the right spot right away!

              If you can reproduce the error, or have a log that shows which method is executed, you'd at least have had a starting point. Then you step through the code.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

              S 1 Reply Last reply
              0
              • S Super Lloyd

                I had the following code in my app. Turns out you just CAN'T debug that code. At least with Visual Studio 2017, It will crash your process instantly and you will be left without any clue as to what was wrong!! Gotta report that to Microsoft.. Meanwhile, behold the evilest safe C# code that can be!

                class Program
                {
                    static void Main(string\[\] args)
                    {
                        try { Fail(); }
                        catch (Exception ex) { Log(ex); }
                    }
                    static void Fail()
                    {
                        throw new NotSupportedException("You Fool!");
                    }
                    static void Log(Exception ex)
                    {
                        var sb = new StringBuilder();
                        Log(ex);
                        Console.WriteLine($"Problem: {sb}");
                    }
                }
                

                [EDIT] To clarify, of course this code is buggy, it's a bug repro. But most remarkably the program just crash without hint from Visual Studio. Even if you ask Visual Studio to stop on StackOverflowException, it won't! [EDIT2] Setting breakpoints is not the problem... But why would you put a breakpoint there if you didn't know the bug was there in the first place? FYI it's about 1 month of work before this bug came to light!

                A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                M Offline
                M Offline
                Marc Clifton
                wrote on last edited by
                #13

                Actually, when you think about it, actually managing to catch an exception in an exception handler that is itself creating a stack overflow, well, that would be impressive.

                Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                S 1 Reply Last reply
                0
                • C CodeWraith

                  To iterate is human, to recurse divine. But not in this case. :-) Of course it does not stop anymore. The process is too busy spiraling down to its death and after that it does not break to report anything. The debugging session is over and the vultures are eating what's left of your process. Would you expect one of the self driving cars to bring you to the hospital after hitting a tree? :-)

                  I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                  R Offline
                  R Offline
                  raddevus
                  wrote on last edited by
                  #14

                  CodeWraith wrote:

                  Would you expect one of the self driving cars to bring you to the hospital after hitting a tree?

                  That's a great analogy. The creation of good strong analogies which lead others to understand things is indication of superior intelligence. Did you steal that analogy from someone else? :rolleyes: See how I set you up? The creation of a setup with an ending punch line is an indication of genius. Someone else gave me the set up and punchline. :laugh: See how I used self-deprecating humor here? It's an indication of superior genius. :laugh:

                  C 1 Reply Last reply
                  0
                  • L Lost User

                    Super Lloyd wrote:

                    That was my problem! Only 600 files changed...

                    All of them using recursion? :)

                    Super Lloyd wrote:

                    Didn't have the insight to put the breakpoint in the right spot right away!

                    If you can reproduce the error, or have a log that shows which method is executed, you'd at least have had a starting point. Then you step through the code.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                    S Offline
                    S Offline
                    Super Lloyd
                    wrote on last edited by
                    #15

                    Eddy Vluggen wrote:

                    All of them using recursion? :)

                    quick questwion, how many method in your code use recusion right now? are you sure? Yeah, just as I thought! ;P

                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                    L 1 Reply Last reply
                    0
                    • M Marc Clifton

                      Actually, when you think about it, actually managing to catch an exception in an exception handler that is itself creating a stack overflow, well, that would be impressive.

                      Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                      S Offline
                      S Offline
                      Super Lloyd
                      wrote on last edited by
                      #16

                      Perhaps, indeed. But that would still be handy! :)

                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                      1 Reply Last reply
                      0
                      • S Super Lloyd

                        Eddy Vluggen wrote:

                        All of them using recursion? :)

                        quick questwion, how many method in your code use recusion right now? are you sure? Yeah, just as I thought! ;P

                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #17

                        Two in the current codebase. Yes, very sure, as I wrote it. Are you saying you are unsure of what code you are writing? :laugh:

                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                        S 1 Reply Last reply
                        0
                        • S Super Lloyd

                          I had the following code in my app. Turns out you just CAN'T debug that code. At least with Visual Studio 2017, It will crash your process instantly and you will be left without any clue as to what was wrong!! Gotta report that to Microsoft.. Meanwhile, behold the evilest safe C# code that can be!

                          class Program
                          {
                              static void Main(string\[\] args)
                              {
                                  try { Fail(); }
                                  catch (Exception ex) { Log(ex); }
                              }
                              static void Fail()
                              {
                                  throw new NotSupportedException("You Fool!");
                              }
                              static void Log(Exception ex)
                              {
                                  var sb = new StringBuilder();
                                  Log(ex);
                                  Console.WriteLine($"Problem: {sb}");
                              }
                          }
                          

                          [EDIT] To clarify, of course this code is buggy, it's a bug repro. But most remarkably the program just crash without hint from Visual Studio. Even if you ask Visual Studio to stop on StackOverflowException, it won't! [EDIT2] Setting breakpoints is not the problem... But why would you put a breakpoint there if you didn't know the bug was there in the first place? FYI it's about 1 month of work before this bug came to light!

                          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                          K Offline
                          K Offline
                          Kevin Marois
                          wrote on last edited by
                          #18

                          I'm using VS2017 and it works as expected

                          If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                          L 1 Reply Last reply
                          0
                          • K Kevin Marois

                            I'm using VS2017 and it works as expected

                            If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #19

                            I'm using VS2017 and it works as expected

                            That means it crashed :laugh:

                            It does not solve my Problem, but it answers my question

                            1 Reply Last reply
                            0
                            • R raddevus

                              CodeWraith wrote:

                              Would you expect one of the self driving cars to bring you to the hospital after hitting a tree?

                              That's a great analogy. The creation of good strong analogies which lead others to understand things is indication of superior intelligence. Did you steal that analogy from someone else? :rolleyes: See how I set you up? The creation of a setup with an ending punch line is an indication of genius. Someone else gave me the set up and punchline. :laugh: See how I used self-deprecating humor here? It's an indication of superior genius. :laugh:

                              C Offline
                              C Offline
                              CodeWraith
                              wrote on last edited by
                              #20

                              raddevus wrote:

                              Did you steal that analogy from someone else? :rolleyes:

                              No. What do you think? I just have some experience with hitting trees with cars.

                              I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                              L 1 Reply Last reply
                              0
                              • C CodeWraith

                                raddevus wrote:

                                Did you steal that analogy from someone else? :rolleyes:

                                No. What do you think? I just have some experience with hitting trees with cars.

                                I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #21

                                experience, experience and again experience.

                                It does not solve my Problem, but it answers my question

                                1 Reply Last reply
                                0
                                • S Super Lloyd

                                  I had the following code in my app. Turns out you just CAN'T debug that code. At least with Visual Studio 2017, It will crash your process instantly and you will be left without any clue as to what was wrong!! Gotta report that to Microsoft.. Meanwhile, behold the evilest safe C# code that can be!

                                  class Program
                                  {
                                      static void Main(string\[\] args)
                                      {
                                          try { Fail(); }
                                          catch (Exception ex) { Log(ex); }
                                      }
                                      static void Fail()
                                      {
                                          throw new NotSupportedException("You Fool!");
                                      }
                                      static void Log(Exception ex)
                                      {
                                          var sb = new StringBuilder();
                                          Log(ex);
                                          Console.WriteLine($"Problem: {sb}");
                                      }
                                  }
                                  

                                  [EDIT] To clarify, of course this code is buggy, it's a bug repro. But most remarkably the program just crash without hint from Visual Studio. Even if you ask Visual Studio to stop on StackOverflowException, it won't! [EDIT2] Setting breakpoints is not the problem... But why would you put a breakpoint there if you didn't know the bug was there in the first place? FYI it's about 1 month of work before this bug came to light!

                                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                  P Offline
                                  P Offline
                                  Paulo Zemek
                                  wrote on last edited by
                                  #22

                                  Are you catching exceptions when they are thrown or only after they are dealt with? If it is the latter, I think that even if you want to catch StackOverflowException's, it will not work because there's no more stack to let you do anything and it is probably using something like Environment.FailFast(). [Environment.FailFast Method (String) (System)](https://msdn.microsoft.com/en-us/library/ms131100(v=vs.110).aspx)

                                  S 1 Reply Last reply
                                  0
                                  • S Super Lloyd

                                    CodeWraith wrote:

                                    Would you expect one of the self driving cars to bring you to the hospital after hitting a tree?

                                    That would be a handy feature! :-D

                                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                    P Offline
                                    P Offline
                                    Paulo Zemek
                                    wrote on last edited by
                                    #23

                                    Would be a handy feature, if it stops hittings trees on the way to the hospital.

                                    1 Reply Last reply
                                    0
                                    • L Lost User

                                      Two in the current codebase. Yes, very sure, as I wrote it. Are you saying you are unsure of what code you are writing? :laugh:

                                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                      S Offline
                                      S Offline
                                      Super Lloyd
                                      wrote on last edited by
                                      #24

                                      Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?) Further this method was not even mean to be recursive.. it's just I got 2 method with the same name but different parameter, just accidentally forgot the extra parameter.. BTW I believe there are 0 recursion in my app but who knows... there was this accidental one for instance...

                                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                      L 1 Reply Last reply
                                      0
                                      • P Paulo Zemek

                                        Are you catching exceptions when they are thrown or only after they are dealt with? If it is the latter, I think that even if you want to catch StackOverflowException's, it will not work because there's no more stack to let you do anything and it is probably using something like Environment.FailFast(). [Environment.FailFast Method (String) (System)](https://msdn.microsoft.com/en-us/library/ms131100(v=vs.110).aspx)

                                        S Offline
                                        S Offline
                                        Super Lloyd
                                        wrote on last edited by
                                        #25

                                        Paulo Zemek wrote:

                                        Are you catching exceptions when they are thrown or only after they are dealt with?

                                        What does that means? I mean what does "catching exception after they are dealt with" means?

                                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                        P 1 Reply Last reply
                                        0
                                        • S Super Lloyd

                                          Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?) Further this method was not even mean to be recursive.. it's just I got 2 method with the same name but different parameter, just accidentally forgot the extra parameter.. BTW I believe there are 0 recursion in my app but who knows... there was this accidental one for instance...

                                          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #26

                                          Super Lloyd wrote:

                                          Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?)

                                          None of those three.

                                          Super Lloyd wrote:

                                          Further this method was not even mean to be recursive.. it's just I got 2 method with the same name but different parameter, just accidentally forgot the extra parameter..

                                          That's why we have logging :)

                                          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                          S 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups