ThreadException event should occur on any unhandled exception in current
thread; example in MSDN throws ArgumentException as well.
Still I don't understand working with unhandled exceptions. In my
application I used Application.ThreadException event to display dialog box
when unhandled exception occured and it worked... until non-catched exception
was thrown from Application.Idle event handler. ThreadException event handler
was not called and standard .NET dialog box appeared advising to send report
to MS.
If I handle AppDomain.CurrentDomain.UnhandledException, 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 ApplicationException, which
> apparently is not the same exception type that you have code to handle for
> (ThreadException).
> Peter
>
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
>
>
> "(E-Mail Removed)" wrote:
>
> > Hi,
> >
> > I have the following Program.cs -
> >
> > namespace TestFrameworkApplication
> > {
> > static class Program
> > {
> > /// <summary>
> > /// The main entry point for the application.
> > /// </summary>
> > [STAThread]
> > static void Main()
> > {
> > Application.EnableVisualStyles();
> > Application.SetCompatibleTextRenderingDefault(false);
> > Application.ThreadException += new
> > ThreadExceptionEventHandler(new
> > ThreadExceptionHandler().ApplicationThreadException);
> > Application.Run(new FormMain());
> > }
> >
> > /// <summary>
> > /// Handles any thread exceptions
> > /// </summary>
> > public class ThreadExceptionHandler
> > {
> > public void ApplicationThreadException(object sender,
> > ThreadExceptionEventArgs e)
> > {
> > MessageBox.Show(e.Exception.Message, "An exception
> > occurred:", MessageBoxButtons.OK, MessageBoxIcon.Error);
> > Application.Exit();
> > }
> > }
> > }
> > }
> >
> > In my Form, I attempt the following -
> >
> > private void button1_Click(object sender, EventArgs e)
> > {
> > ThrowException();
> > }
> >
> > private void ThrowException()
> > {
> > throw new ApplicationException("Monkey exception");
> > }
> >
> > But when I click on the corresponding button, I keep getting the
> > message "ApplicationException 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.
> >
> >