Nice exceptions.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • craigkenisston@hotmail.com

    Nice exceptions.

    I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
    like this.

    My code looks like :

    try
    {
    blah
    blah
    blah
    }
    catch (Exception)
    {
    MyOwnException myoe = new MyOwnException ("Error on receiving data");
    throw myoe;
    }

    And what I get when an error happens is a window telling me :
    "Applicatio n1 has encountered a problem and needs to close.
    Send Error Report Don't Send"

    Then after clicking either "Send" or "Not Send", the windows closes and
    the program vanishes.

    As far as I remember I'm catching the exception and the program should
    be keep working after that.

    Where's my fault ?

  • Tom Shelton

    #2
    Re: Nice exceptions.


    craigkenisston@ hotmail.com wrote:
    I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
    like this.
    >
    My code looks like :
    >
    try
    {
    blah
    blah
    blah
    }
    catch (Exception)
    {
    MyOwnException myoe = new MyOwnException ("Error on receiving data");
    throw myoe;
    }
    >
    And what I get when an error happens is a window telling me :
    "Applicatio n1 has encountered a problem and needs to close.
    Send Error Report Don't Send"
    >
    Then after clicking either "Send" or "Not Send", the windows closes and
    the program vanishes.
    >
    As far as I remember I'm catching the exception and the program should
    be keep working after that.
    >
    Where's my fault ?
    You throw an exception from you catch block - where is that being
    caught? In other words, it appears that the MyOwnException is not
    beign caught.

    --
    Tom Shelton

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Nice exceptions.

      <craigkenisston @hotmail.comwro te:
      I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
      like this.
      >
      My code looks like :
      <snip>
      As far as I remember I'm catching the exception and the program should
      be keep working after that.
      >
      Where's my fault ?
      Well, you're throwing another exception after you've caught the
      original one...

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      • sloan

        #4
        Re: Nice exceptions.


        I usually create a class, called

        EntryPoint.cs


        [STAThread]
        static void Main(string[] args)
        {
        try
        {

        Application.Run (new Form1()); //Whatever your startup form is

        }

        }
        catch (Exception ex)
        {
        //Notify User
        MessageBox.Show ( "A (uncaught) exception has occured. MyApp
        cannot continue." );
        //Shut down application
        Application.Exi t( );
        }
        }


        This will catch any uncaught exceptions.

        But Jon is right.
        You catch an general exception, but you're rethrowing it.
        Thus something else must catch it, or you'll get the blow-up screen.


        You should should google

        try catch finally brad abrams

        and you can read where

        "You should be writing many many more

        try/finally
        blocks

        and not so many
        try/catch/finally

        blocks.





        <craigkenisston @hotmail.comwro te in message
        news:1158866316 .744452.190120@ e3g2000cwe.goog legroups.com...
        I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
        like this.
        >
        My code looks like :
        >
        try
        {
        blah
        blah
        blah
        }
        catch (Exception)
        {
        MyOwnException myoe = new MyOwnException ("Error on receiving data");
        throw myoe;
        }
        >
        And what I get when an error happens is a window telling me :
        "Applicatio n1 has encountered a problem and needs to close.
        Send Error Report Don't Send"
        >
        Then after clicking either "Send" or "Not Send", the windows closes and
        the program vanishes.
        >
        As far as I remember I'm catching the exception and the program should
        be keep working after that.
        >
        Where's my fault ?
        >

        Comment

        • craigkenisston@hotmail.com

          #5
          Re: Nice exceptions.


          My complain is not why it is thrown, but why the application closes...
          and I figured out why, but yet need to know how to workaround it.

          The problem was this: it was on an thread.
          If I run the same code without threading, the error is shown in a nicer
          box with "Stop" and "Continue" buttons. Then the application doesn't
          close on the error.

          Now, the question, is it normal with a threaded application that a
          thrown exception put the application down ?




          sloan wrote:
          I usually create a class, called
          >
          EntryPoint.cs
          >
          >
          [STAThread]
          static void Main(string[] args)
          {
          try
          {
          >
          Application.Run (new Form1()); //Whatever your startup form is
          >
          }
          >
          }
          catch (Exception ex)
          {
          //Notify User
          MessageBox.Show ( "A (uncaught) exception has occured. MyApp
          cannot continue." );
          //Shut down application
          Application.Exi t( );
          }
          }
          >
          >
          This will catch any uncaught exceptions.
          >
          But Jon is right.
          You catch an general exception, but you're rethrowing it.
          Thus something else must catch it, or you'll get the blow-up screen.
          >
          >
          You should should google
          >
          try catch finally brad abrams
          >
          and you can read where
          >
          "You should be writing many many more
          >
          try/finally
          blocks
          >
          and not so many
          try/catch/finally
          >
          blocks.
          >
          >
          >
          >
          >
          <craigkenisston @hotmail.comwro te in message
          news:1158866316 .744452.190120@ e3g2000cwe.goog legroups.com...
          I'm new to VS2005, I used VS2003 a bit, and I remember it didn't act
          like this.

          My code looks like :

          try
          {
          blah
          blah
          blah
          }
          catch (Exception)
          {
          MyOwnException myoe = new MyOwnException ("Error on receiving data");
          throw myoe;
          }

          And what I get when an error happens is a window telling me :
          "Applicatio n1 has encountered a problem and needs to close.
          Send Error Report Don't Send"

          Then after clicking either "Send" or "Not Send", the windows closes and
          the program vanishes.

          As far as I remember I'm catching the exception and the program should
          be keep working after that.

          Where's my fault ?

          Comment

          • Doug Forster

            #6
            Re: Nice exceptions.

            Now, the question, is it normal with a threaded application that a
            thrown exception put the application down ?
            As of .NET 2 that is indeed the normal behaviour.
            ..NET 1 behaviour was to silently terminate the thread

            You need to handle the exception in the thread

            Cheers
            Doug Forster


            Comment

            • craigkenisston@hotmail.com

              #7
              Re: Nice exceptions.

              Ok, good to know, thanks a lot !



              Doug Forster wrote:
              Now, the question, is it normal with a threaded application that a
              thrown exception put the application down ?
              >
              As of .NET 2 that is indeed the normal behaviour.
              .NET 1 behaviour was to silently terminate the thread
              >
              You need to handle the exception in the thread
              >
              Cheers
              Doug Forster

              Comment

              Working...