Global Exception Handling in VB.NET?

samer_ali

Member
Joined
Feb 16, 2004
Messages
11
how can i can handle global expception in vb.net?

and i want to handle every error happen with out adding Try and End Try is this possible?

thanks
 
yes, its possible

here is a piece of code that will help you with that

On the load evento of the main form
C#:
AppDom.UnhandledException += new UnhandledExceptionEventHandler(this.GLOBALERRORHANDLER);
Application.ThreadException +=new ThreadExceptionEventHandler(this.THREADERRORHANDLER);

this are the handlers youll create for the Global Error and the Thread Errors

C#:
private void GLOBALERRORHANDLER(object sender, UnhandledExceptionEventArgs args)
{
	Exception ex = (Exception)args.ExceptionObject;
	FrmError frmErr = new FrmError();
	frmErr.p_Message = ex.Message.ToString() + " *****" +
	ex.Source.ToString() + " *****" + ex.StackTrace.ToString() +
				" *****" + ex.TargetSite.ToString();
	frmErr.MdiParent = this;
	frmErr.StartPosition = FormStartPosition.CenterScreen;
	frmErr.Show();
}

private void THREADERRORHANDLER(object sender, ThreadExceptionEventArgs args)
{
	Exception ex = (Exception)args.Exception;
	FrmError frmErr = new FrmError();
	frmErr.p_Message = ex.Message.ToString() + " *****" +
	ex.Source.ToString() + " *****" + ex.StackTrace.ToString() +
	" *****" + ex.TargetSite.ToString();
	frmErr.MdiParent = this;
	frmErr.StartPosition = FormStartPosition.CenterScreen;
	frmErr.Show();
}

if you have any problems postem here
 
Back
Top