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. Windows swallows exceptions

Windows swallows exceptions

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdotnetcomdesignbeta-testing
14 Posts 5 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.
  • N Nicholas Marty

    There are two ways to crash your application: - The exception occurred on the main thread (that is the same as where the main function is called) - Corrupted State Exceptions that you usually just can't handle (e.g. AccessViolationException, StackOverflowException (if thrown by the OS), etc.) and the application just isn't in a state where it could continue (Yeah, I know, you CAN catch an AccessViolationException, but it's generally not encouraged) I don't see any reason why an entire application should go boom because one single thread messed something up ;)

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #5

    Nicholas Marty wrote:

    I don't see any reason why an entire application should go boom because one single thread messed something up ;)

    1. So that you know it did! Trying to save people from themselves is not generally a worthwhile endeavor.

    This space intentionally left blank.

    1 Reply Last reply
    0
    • S Sentenryu

      And if it did not swallow the exception, your entire application would go down with a unhandled exception. I guess the designers decided that it was better to not let the application die due to a simple timed event (that would likely execute again)

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #6

      Sentenryu wrote:

      I guess the designers decided that it was better to not let the application die due to a simple timed event (that would likely execute again)

      Let the developer decide what to do; it's not your job.

      This space intentionally left blank.

      S 1 Reply Last reply
      0
      • N Nicholas Marty

        There are two ways to crash your application: - The exception occurred on the main thread (that is the same as where the main function is called) - Corrupted State Exceptions that you usually just can't handle (e.g. AccessViolationException, StackOverflowException (if thrown by the OS), etc.) and the application just isn't in a state where it could continue (Yeah, I know, you CAN catch an AccessViolationException, but it's generally not encouraged) I don't see any reason why an entire application should go boom because one single thread messed something up ;)

        S Offline
        S Offline
        Sentenryu
        wrote on last edited by
        #7

        run this:

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Threading;
        using System.Threading.Tasks;

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

                new Thread(\_ => { throw new ArgumentException(); }).Start();
        
                for (int i = 0; i < 1000; i++) {
                    Console.WriteLine("Wasting time...");
                }
        
                Console.ReadKey();
            }
        }
        

        }

        The application crashes with an unhandled exception. ANY unhandled exception on ANY thread crashes the app. I Learned this from C# 5.0 in a nutshell from john albahari, here's an excerpt:

        Quote:

        AppDomain.CurrentDomain.UnhandledException fires on any unhandled exception on any thread, but since CLR 2.0, the CLR forces application shutdown after your event handler completes.

        Also, for anyone reading this, I strongly recomend that book.

        P J 2 Replies Last reply
        0
        • P PIEBALDconsult

          Sentenryu wrote:

          I guess the designers decided that it was better to not let the application die due to a simple timed event (that would likely execute again)

          Let the developer decide what to do; it's not your job.

          This space intentionally left blank.

          S Offline
          S Offline
          Sentenryu
          wrote on last edited by
          #8

          PIEBALDconsult wrote:

          it's not your job.

          Apparently, they disagree :laugh:

          P 1 Reply Last reply
          0
          • S Sentenryu

            PIEBALDconsult wrote:

            it's not your job.

            Apparently, they disagree :laugh:

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #9

            <mumbling>Self-righteous b-tards...</mumbling>

            This space intentionally left blank.

            1 Reply Last reply
            0
            • S Sentenryu

              run this:

              using System;
              using System.Collections.Generic;
              using System.Linq;
              using System.Text;
              using System.Threading;
              using System.Threading.Tasks;

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

                      new Thread(\_ => { throw new ArgumentException(); }).Start();
              
                      for (int i = 0; i < 1000; i++) {
                          Console.WriteLine("Wasting time...");
                      }
              
                      Console.ReadKey();
                  }
              }
              

              }

              The application crashes with an unhandled exception. ANY unhandled exception on ANY thread crashes the app. I Learned this from C# 5.0 in a nutshell from john albahari, here's an excerpt:

              Quote:

              AppDomain.CurrentDomain.UnhandledException fires on any unhandled exception on any thread, but since CLR 2.0, the CLR forces application shutdown after your event handler completes.

              Also, for anyone reading this, I strongly recomend that book.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #10

              As well it should; what's your point?

              This space intentionally left blank.

              S 1 Reply Last reply
              0
              • P PIEBALDconsult

                As well it should; what's your point?

                This space intentionally left blank.

                S Offline
                S Offline
                Sentenryu
                wrote on last edited by
                #11

                I was just giving my 2 cents on why that design decision might have been made, without getting into the merit of saying if it's the right way™ or not. I do defend the crash on this situation, as there's no way to know if the thread ended on a valid state or not. I interpreted Nicholas Marty's answer as saying that those are the only ways an application might terminate due to an unhandled exception, and felt the necessity to point out that an unhandled exception on any thread would terminate the application, and not just on the main thread, as was implied. It's also worth noting that if the unhandled exception is on another app domain, you can just handle the AppDomain.CurrentDomain.UnhandledException trashing the offending app domain, then continuing to run normally.

                1 Reply Last reply
                0
                • S Sentenryu

                  run this:

                  using System;
                  using System.Collections.Generic;
                  using System.Linq;
                  using System.Text;
                  using System.Threading;
                  using System.Threading.Tasks;

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

                          new Thread(\_ => { throw new ArgumentException(); }).Start();
                  
                          for (int i = 0; i < 1000; i++) {
                              Console.WriteLine("Wasting time...");
                          }
                  
                          Console.ReadKey();
                      }
                  }
                  

                  }

                  The application crashes with an unhandled exception. ANY unhandled exception on ANY thread crashes the app. I Learned this from C# 5.0 in a nutshell from john albahari, here's an excerpt:

                  Quote:

                  AppDomain.CurrentDomain.UnhandledException fires on any unhandled exception on any thread, but since CLR 2.0, the CLR forces application shutdown after your event handler completes.

                  Also, for anyone reading this, I strongly recomend that book.

                  J Offline
                  J Offline
                  johannesnestler
                  wrote on last edited by
                  #12

                  Hi Sentenryu, Run this:

                  using System;
                  using System.Timers;

                  namespace TimerTest
                  {
                  static class Program
                  {
                  [STAThread]
                  static void Main()
                  {
                  System.Timers.Timer timer = new Timer();
                  timer.Elapsed += (object sender, ElapsedEventArgs e) => { throw new NotImplementedException(); };
                  timer.Start();

                          Console.ReadKey();
                      }
                  }
                  

                  }

                  I think OP's point was, that in some circumstances your "rule" (from the very good book) doesn't apply. If you don't know the documented behaviour in this case, you may scratch your head like OP did... :wtf:

                  S 1 Reply Last reply
                  0
                  • J johannesnestler

                    Hi Sentenryu, Run this:

                    using System;
                    using System.Timers;

                    namespace TimerTest
                    {
                    static class Program
                    {
                    [STAThread]
                    static void Main()
                    {
                    System.Timers.Timer timer = new Timer();
                    timer.Elapsed += (object sender, ElapsedEventArgs e) => { throw new NotImplementedException(); };
                    timer.Start();

                            Console.ReadKey();
                        }
                    }
                    

                    }

                    I think OP's point was, that in some circumstances your "rule" (from the very good book) doesn't apply. If you don't know the documented behaviour in this case, you may scratch your head like OP did... :wtf:

                    S Offline
                    S Offline
                    Sentenryu
                    wrote on last edited by
                    #13

                    you didn't read the full thread... the message before the one you replied states that the timer class catches the exceptions, and that is documented:

                    Quote:

                    In the .NET Framework version 2.0 and earlier, the Timer component catches and suppresses all exceptions thrown by event handlers for the Elapsed event. This behavior is subject to change in future releases of the .NET Framework.

                    MSDN link: http://msdn.microsoft.com/pt-BR/library/system.timers.timer%28v=vs.110%29.aspx[^]

                    J 1 Reply Last reply
                    0
                    • S Sentenryu

                      you didn't read the full thread... the message before the one you replied states that the timer class catches the exceptions, and that is documented:

                      Quote:

                      In the .NET Framework version 2.0 and earlier, the Timer component catches and suppresses all exceptions thrown by event handlers for the Elapsed event. This behavior is subject to change in future releases of the .NET Framework.

                      MSDN link: http://msdn.microsoft.com/pt-BR/library/system.timers.timer%28v=vs.110%29.aspx[^]

                      J Offline
                      J Offline
                      johannesnestler
                      wrote on last edited by
                      #14

                      Ah you are right - sorry for overseeing your first post - So Forget my post. :-O But at least I knew about this and that it's documented - thank you anyway for clarification

                      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