ApplicationException unhandled by user code

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

    #1

    ApplicationException unhandled by user code

    Hi,

    I have the following Program.cs -

    namespace TestFrameworkAp plication
    {
    static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
    Application.Ena bleVisualStyles ();
    Application.Set CompatibleTextR enderingDefault (false);
    Application.Thr eadException += new
    ThreadException EventHandler(ne w
    ThreadException Handler().Appli cationThreadExc eption);
    Application.Run (new FormMain());
    }

    /// <summary>
    /// Handles any thread exceptions
    /// </summary>
    public class ThreadException Handler
    {
    public void ApplicationThre adException(obj ect sender,
    ThreadException EventArgs e)
    {
    MessageBox.Show (e.Exception.Me ssage, "An exception
    occurred:", MessageBoxButto ns.OK, MessageBoxIcon. Error);
    Application.Exi t();
    }
    }
    }
    }

    In my Form, I attempt the following -

    private void button1_Click(o bject sender, EventArgs e)
    {
    ThrowException( );
    }

    private void ThrowException( )
    {
    throw new ApplicationExce ption("Monkey exception");
    }

    But when I click on the corresponding button, I keep getting the
    message "ApplicationExc eption unhandled by user code" from the
    debugger. But once I continue the debugger, the message box pops up
    with the error. What is the debugger warning me about and can I switch
    off this message if I am not actually doing anything incorrect?

    Thanks for your help,

    Barry.

  • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    #2
    RE: ApplicationExce ption unhandled by user code

    It seems to me that you are throwing an ApplicationExce ption, which
    apparently is not the same exception type that you have code to handle for
    (ThreadExceptio n).
    Peter

    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "bg_ie@yahoo.co m" wrote:
    Hi,
    >
    I have the following Program.cs -
    >
    namespace TestFrameworkAp plication
    {
    static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
    Application.Ena bleVisualStyles ();
    Application.Set CompatibleTextR enderingDefault (false);
    Application.Thr eadException += new
    ThreadException EventHandler(ne w
    ThreadException Handler().Appli cationThreadExc eption);
    Application.Run (new FormMain());
    }
    >
    /// <summary>
    /// Handles any thread exceptions
    /// </summary>
    public class ThreadException Handler
    {
    public void ApplicationThre adException(obj ect sender,
    ThreadException EventArgs e)
    {
    MessageBox.Show (e.Exception.Me ssage, "An exception
    occurred:", MessageBoxButto ns.OK, MessageBoxIcon. Error);
    Application.Exi t();
    }
    }
    }
    }
    >
    In my Form, I attempt the following -
    >
    private void button1_Click(o bject sender, EventArgs e)
    {
    ThrowException( );
    }
    >
    private void ThrowException( )
    {
    throw new ApplicationExce ption("Monkey exception");
    }
    >
    But when I click on the corresponding button, I keep getting the
    message "ApplicationExc eption unhandled by user code" from the
    debugger. But once I continue the debugger, the message box pops up
    with the error. What is the debugger warning me about and can I switch
    off this message if I am not actually doing anything incorrect?
    >
    Thanks for your help,
    >
    Barry.
    >
    >

    Comment

    • =?Utf-8?B?U2l2YSBN?=

      #3
      RE: ApplicationExce ption unhandled by user code

      Try this:

      Go to VS 2005 menu Tools | Options and then Debugging/General. Uncheck
      'Enable Just my Code'.

      "bg_ie@yahoo.co m" wrote:
      Hi,
      >
      I have the following Program.cs -
      >
      namespace TestFrameworkAp plication
      {
      static class Program
      {
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
      Application.Ena bleVisualStyles ();
      Application.Set CompatibleTextR enderingDefault (false);
      Application.Thr eadException += new
      ThreadException EventHandler(ne w
      ThreadException Handler().Appli cationThreadExc eption);
      Application.Run (new FormMain());
      }
      >
      /// <summary>
      /// Handles any thread exceptions
      /// </summary>
      public class ThreadException Handler
      {
      public void ApplicationThre adException(obj ect sender,
      ThreadException EventArgs e)
      {
      MessageBox.Show (e.Exception.Me ssage, "An exception
      occurred:", MessageBoxButto ns.OK, MessageBoxIcon. Error);
      Application.Exi t();
      }
      }
      }
      }
      >
      In my Form, I attempt the following -
      >
      private void button1_Click(o bject sender, EventArgs e)
      {
      ThrowException( );
      }
      >
      private void ThrowException( )
      {
      throw new ApplicationExce ption("Monkey exception");
      }
      >
      But when I click on the corresponding button, I keep getting the
      message "ApplicationExc eption unhandled by user code" from the
      debugger. But once I continue the debugger, the message box pops up
      with the error. What is the debugger warning me about and can I switch
      off this message if I am not actually doing anything incorrect?
      >
      Thanks for your help,
      >
      Barry.
      >
      >

      Comment

      • bg_ie@yahoo.com

        #4
        Re: ApplicationExce ption unhandled by user code

        On 24 Apr, 13:04, Siva M <shiva...@onlin e.excite.comwro te:
        Try this:
        >
        Go to VS 2005 menu Tools | Options and then Debugging/General. Uncheck
        'Enable Just my Code'.
        >
        >
        >
        "b...@yahoo.com " wrote:
        Hi,
        >
        I have the following Program.cs -
        >
        namespace TestFrameworkAp plication
        {
        static class Program
        {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
        Application.Ena bleVisualStyles ();
        Application.Set CompatibleTextR enderingDefault (false);
        Application.Thr eadException += new
        ThreadException EventHandler(ne w
        ThreadException Handler().Appli cationThreadExc eption);
        Application.Run (new FormMain());
        }
        >
        /// <summary>
        /// Handles any thread exceptions
        /// </summary>
        public class ThreadException Handler
        {
        public void ApplicationThre adException(obj ect sender,
        ThreadException EventArgs e)
        {
        MessageBox.Show (e.Exception.Me ssage, "An exception
        occurred:", MessageBoxButto ns.OK, MessageBoxIcon. Error);
        Application.Exi t();
        }
        }
        }
        }
        >
        In my Form, I attempt the following -
        >
        private void button1_Click(o bject sender, EventArgs e)
        {
        ThrowException( );
        }
        >
        private void ThrowException( )
        {
        throw new ApplicationExce ption("Monkey exception");
        }
        >
        But when I click on the corresponding button, I keep getting the
        message "ApplicationExc eption unhandled by user code" from the
        debugger. But once I continue the debugger, the message box pops up
        with the error. What is the debugger warning me about and can I switch
        off this message if I am not actually doing anything incorrect?
        >
        Thanks for your help,
        >
        Barry.- Dölj citerad text -
        >
        - Visa citerad text -
        That worked, thanks. But why did it work?

        Comment

        • =?Utf-8?B?UGVwYQ==?=

          #5
          RE: ApplicationExce ption unhandled by user code

          ThreadException event should occur on any unhandled exception in current
          thread; example in MSDN throws ArgumentExcepti on as well.

          Still I don't understand working with unhandled exceptions. In my
          application I used Application.Thr eadException event to display dialog box
          when unhandled exception occured and it worked... until non-catched exception
          was thrown from Application.Idl e event handler. ThreadException event handler
          was not called and standard .NET dialog box appeared advising to send report
          to MS.

          If I handle AppDomain.Curre ntDomain.Unhand ledException, this handler *is*
          called when exception in Idle occurs. But it only informs about exception.
          When my handler ends, standard .NET crash dialog box appears again.

          The exception in Idle handler can also be caught by sorrounding
          Application.Run with try-catch. But that would require some "goto" or "while"
          to resume the application if I wish to continue after exception.

          I cannot make head of it:)

          Pepa

          "Peter Bromberg [C# MVP]" wrote:
          It seems to me that you are throwing an ApplicationExce ption, which
          apparently is not the same exception type that you have code to handle for
          (ThreadExceptio n).
          Peter
          >
          --
          Site: http://www.eggheadcafe.com
          UnBlog: http://petesbloggerama.blogspot.com
          Short urls & more: http://ittyurl.net
          >
          >
          >
          >
          "bg_ie@yahoo.co m" wrote:
          >
          Hi,

          I have the following Program.cs -

          namespace TestFrameworkAp plication
          {
          static class Program
          {
          /// <summary>
          /// The main entry point for the application.
          /// </summary>
          [STAThread]
          static void Main()
          {
          Application.Ena bleVisualStyles ();
          Application.Set CompatibleTextR enderingDefault (false);
          Application.Thr eadException += new
          ThreadException EventHandler(ne w
          ThreadException Handler().Appli cationThreadExc eption);
          Application.Run (new FormMain());
          }

          /// <summary>
          /// Handles any thread exceptions
          /// </summary>
          public class ThreadException Handler
          {
          public void ApplicationThre adException(obj ect sender,
          ThreadException EventArgs e)
          {
          MessageBox.Show (e.Exception.Me ssage, "An exception
          occurred:", MessageBoxButto ns.OK, MessageBoxIcon. Error);
          Application.Exi t();
          }
          }
          }
          }

          In my Form, I attempt the following -

          private void button1_Click(o bject sender, EventArgs e)
          {
          ThrowException( );
          }

          private void ThrowException( )
          {
          throw new ApplicationExce ption("Monkey exception");
          }

          But when I click on the corresponding button, I keep getting the
          message "ApplicationExc eption unhandled by user code" from the
          debugger. But once I continue the debugger, the message box pops up
          with the error. What is the debugger warning me about and can I switch
          off this message if I am not actually doing anything incorrect?

          Thanks for your help,

          Barry.

          Comment

          Working...