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.
  • 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
              • L Lost User

                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 Offline
                S Offline
                Super Lloyd
                wrote on last edited by
                #27

                well.. it was a bug in the logging class, if you must know...

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

                1 Reply Last reply
                0
                • L Lost User

                  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 Offline
                  S Offline
                  Super Lloyd
                  wrote on last edited by
                  #28

                  Eddy Vluggen wrote:

                  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.

                  Ha! I was already old when the earth was young!

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

                  L 1 Reply Last reply
                  0
                  • S Super Lloyd

                    Eddy Vluggen wrote:

                    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.

                    Ha! I was already old when the earth was young!

                    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
                    #29

                    No, but experienced enough to add a hint in XML comment when recursion is used. Logging is easily tested with unit-tests. Anything else? :)

                    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
                    • L Lost User

                      No, but experienced enough to add a hint in XML comment when recursion is used. Logging is easily tested with unit-tests. Anything else? :)

                      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
                      #30

                      Yeah, you should work on your communication skills. Also, most of this codebase is written for being hard to test. One of the thing I am changing. Though I was not planning to using test every single method or allegedly trivial ones... nor every single parameter... (more than a bazillion possible combination there) Beside my fake test application with all the real code except fake - virtual faster hardware was also crashing mysteriously. Bummer.

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

                      L 1 Reply Last reply
                      0
                      • S Super Lloyd

                        Yeah, you should work on your communication skills. Also, most of this codebase is written for being hard to test. One of the thing I am changing. Though I was not planning to using test every single method or allegedly trivial ones... nor every single parameter... (more than a bazillion possible combination there) Beside my fake test application with all the real code except fake - virtual faster hardware was also crashing mysteriously. Bummer.

                        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
                        #31

                        Super Lloyd wrote:

                        Yeah, you should work on your communication skills.

                        I don't work in marketing.

                        Super Lloyd wrote:

                        Also, most of this codebase is written for being hard to test. One of the thing I am changing.

                        I'd expect a logger to be some independent item, or even framework.

                        Super Lloyd wrote:

                        Though I was not planning to using test every single method or allegedly trivial ones... nor every single parameter... (more than a bazillion possible combination there)

                        Depending on how large the code-base is, testing everything is rather unrealistic. And yes, brownfields are the prime source for material for the Weird & Wonderfull forum here :)

                        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.

                        1 Reply Last reply
                        0
                        • S Super Lloyd

                          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 Offline
                          P Offline
                          Paulo Zemek
                          wrote on last edited by
                          #32

                          You can debug exceptions when they are thrown. This means you stop even if there's a catch block that's going to "eat" the exception. Or, you can debug only exceptions that are uncaught or are rethrown. In this case, if there's a catch clause, you will not see the exception until it is rethrown (if it ever is rethrown). Usually on the second case, an exception that kills the application will not give you a chance to debug it. On the first case, you usually have that option (and for an exception throwing another exception, throwing another exception you would be bothered thousand of times before the app is killed).

                          1 Reply 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