Re: killing a process from task manager does not fire console CTRL_CLOSE_EVENT
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Thu, 22 Dec 2005 21:02:28 +0100
"shiry" <shiryb@xxxxxxxxx> wrote in message
news:1135250894.371967.225920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> What do you mean by: "install a catch handler"?
> (I'm pretty new to all this programming business, so excuse me for my
> novice questions)
>
Something like this for a console program, will catch unhandled
exceptions...
public static void DoSomethingNasty()
{
int x=0,y=1;
Console.Write((y/x).ToString()); // this will throw a "devide by zero"
exception
}
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(GenericErrorHandler);
// Start a thread and do something bad...
Thread t = new Thread(new ThreadStart(DoSomethingNasty));
t.Start();
t.Join();
}
static void GenericErrorHandler(object sender,UnhandledExceptionEventArgs
e)
{
Console.WriteLine("Exiting...");
System.Environment.Exit(1); // terminate process and return error code
1 to parent process
}
Note that this doesn't catch process terminated by a "Kill" command!!!
Willy.
.
- Follow-Ups:
- References:
- killing a process from task manager does not fire console CTRL_CLOSE_EVENT
- From: shiry
- Re: killing a process from task manager does not fire console CTRL_CLOSE_EVENT
- From: shiry
- Re: killing a process from task manager does not fire console CTRL_CLOSE_EVENT
- From: Willy Denoyette [MVP]
- Re: killing a process from task manager does not fire console CTRL_CLOSE_EVENT
- From: shiry
- killing a process from task manager does not fire console CTRL_CLOSE_EVENT
- Prev by Date: Re: dataset reuse
- Next by Date: Re: TCP - Outstanding Begin Receives
- Previous by thread: Re: killing a process from task manager does not fire console CTRL_CLOSE_EVENT
- Next by thread: Re: killing a process from task manager does not fire console CTRL_CLOSE_EVENT
- Index(es):