Click here to Skip to main content
15,922,584 members
Home / Discussions / C#
   

C#

 
GeneralRe: uncaught exception handlers Pin
Derek Bartram27-Apr-08 0:12
Derek Bartram27-Apr-08 0:12 
GeneralRe: uncaught exception handlers Pin
George_George27-Apr-08 2:08
George_George27-Apr-08 2:08 
GeneralRe: uncaught exception handlers Pin
Derek Bartram30-Apr-08 1:49
Derek Bartram30-Apr-08 1:49 
GeneralRe: uncaught exception handlers Pin
George_George30-Apr-08 3:58
George_George30-Apr-08 3:58 
GeneralRe: uncaught exception handlers Pin
Derek Bartram30-Apr-08 4:54
Derek Bartram30-Apr-08 4:54 
GeneralRe: uncaught exception handlers Pin
George_George30-Apr-08 5:08
George_George30-Apr-08 5:08 
GeneralRe: uncaught exception handlers Pin
PIEBALDconsult27-Apr-08 4:37
mvePIEBALDconsult27-Apr-08 4:37 
GeneralRe: uncaught exception handlers Pin
Derek Bartram27-Apr-08 6:56
Derek Bartram27-Apr-08 6:56 
GeneralRe: uncaught exception handlers Pin
George_George27-Apr-08 20:17
George_George27-Apr-08 20:17 
GeneralRe: uncaught exception handlers Pin
Derek Bartram30-Apr-08 5:08
Derek Bartram30-Apr-08 5:08 
GeneralRe: uncaught exception handlers Pin
George_George30-Apr-08 5:11
George_George30-Apr-08 5:11 
GeneralRe: uncaught exception handlers Pin
Derek Bartram30-Apr-08 5:48
Derek Bartram30-Apr-08 5:48 
GeneralRe: uncaught exception handlers Pin
George_George1-May-08 2:13
George_George1-May-08 2:13 
GeneralRe: uncaught exception handlers Pin
Derek Bartram1-May-08 2:20
Derek Bartram1-May-08 2:20 
GeneralRe: uncaught exception handlers Pin
George_George1-May-08 2:45
George_George1-May-08 2:45 
GeneralRe: uncaught exception handlers Pin
George_George27-Apr-08 19:56
George_George27-Apr-08 19:56 
GeneralRe: uncaught exception handlers Pin
George_George26-Apr-08 21:06
George_George26-Apr-08 21:06 
GeneralRe: uncaught exception handlers Pin
N a v a n e e t h26-Apr-08 6:15
N a v a n e e t h26-Apr-08 6:15 
GeneralRe: uncaught exception handlers Pin
George_George26-Apr-08 21:04
George_George26-Apr-08 21:04 
GeneralRe: uncaught exception handlers Pin
N a v a n e e t h27-Apr-08 19:49
N a v a n e e t h27-Apr-08 19:49 
GeneralRe: uncaught exception handlers Pin
George_George27-Apr-08 19:55
George_George27-Apr-08 19:55 
GeneralRe: uncaught exception handlers Pin
N a v a n e e t h27-Apr-08 22:38
N a v a n e e t h27-Apr-08 22:38 
GeneralRe: uncaught exception handlers Pin
George_George28-Apr-08 1:20
George_George28-Apr-08 1:20 
GeneralRe: uncaught exception handlers Pin
N a v a n e e t h28-Apr-08 19:49
N a v a n e e t h28-Apr-08 19:49 
GeneralRe: uncaught exception handlers Pin
George_George29-Apr-08 2:25
George_George29-Apr-08 2:25 
Thanks N a v a n e e t h,


1.

Seems UnhandledException is the only approach to handle exception from other threads, and I have tried even ProcessExit does not work. Here is my code to test. Could you review whether my code and my points are correct? Smile | :)

2.

After the handler for UnhandledException is executed, process is always terminated?

using System;
using System.Threading;

namespace DelegateThread
{
    class Test
    {
        private static void Method2 (object input)
        {
            Console.WriteLine("Method1 is throwing exception");
            throw new ApplicationException("**** oops ****");
        }

        private static void Method1()
        {
            Console.WriteLine("Method1 is throwing exception");
            throw new ApplicationException("**** oops ****");
        }

        private static void Handler1 (object sender, EventArgs e)
        {
            Console.WriteLine ("I am here");
        }

        private static void Handler3(object sender, EventArgs e)
        {
            Console.WriteLine("I am here");
        }

        delegate void Method1Delegate();

        static void Main(string[] args)
        {
            Console.WriteLine("We first use a thread");

            AppDomain.CurrentDomain.ProcessExit += new EventHandler (Test.Handler1);
            AppDomain.CurrentDomain.UnhandledException +=new UnhandledExceptionEventHandler(Test.Handler3);
            
            Thread aThread
                = new Thread(new ThreadStart(Method1));
            aThread.Start();
            


            Thread.Sleep(5000);

            Console.WriteLine("Survived exception");

            return;

        } // main
    }
}



regards,
George

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.