Will this do the global error handling?

J

John

Hi

My vb.net winform app has frmMyForm as the start-up form. I have enclosed
My.Forms.frmMyForm.Show() within try/catch. Will this do the trick of
handling all exceptions that have not been handled elsewhere?

Thanks

Regards


Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As
Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles
Me.Startup
Try
My.Forms.frmMyForm.Show()
Catch ex As Exception
' Exception handling here
End Try
End Sub
 
P

pvdg42

John said:
Hi

My vb.net winform app has frmMyForm as the start-up form. I have enclosed
My.Forms.frmMyForm.Show() within try/catch. Will this do the trick of
handling all exceptions that have not been handled elsewhere?

Thanks

Regards


Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As
Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles
Me.Startup
Try
My.Forms.frmMyForm.Show()
Catch ex As Exception
' Exception handling here
End Try
End Sub
In terms of preventing the default exception handler from terminating your
app, I guess you could say it would work. In terms of providing a context
sensitive response to a given exception and giving your application a chance
to recover and continue, it's not going to be useful.
 
J

John

What can I do to improve?

Thanks

Regards

pvdg42 said:
In terms of preventing the default exception handler from terminating your
app, I guess you could say it would work. In terms of providing a context
sensitive response to a given exception and giving your application a
chance to recover and continue, it's not going to be useful.
 
M

Michael Nemtsev

Hello John,

You need to guard against unhandled exceptions by registering a handler for
them.
Just add a ThreadExceptionEventHandler to the Application.ThreadException
delegate

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

J> What can I do to improve?
J>
J> Thanks
J>
J> Regards
J>
J> J>
 
J

John

Hi Michael

Thanks. Is there an example somewhere I can look at as to how to do some
comprehensive exception handling with option to email log to the developer?

Many Thanks

Regards

Michael Nemtsev said:
Hello John,

You need to guard against unhandled exceptions by registering a handler
for them.
Just add a ThreadExceptionEventHandler to the Application.ThreadException
delegate

---
WBR, Michael Nemtsev [.NET/C# MVP]. My blog:
http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

J> What can I do to improve?
J> J> Thanks
J> J> Regards
J> J>
 
M

Michael Nemtsev

Hello John,

Smth like

AddHandler Application.ThreadException, _
New ThreadExceptionEventHandler( _
AddressOf Application_ThreadException)

at your main method, and handler

Private Shared Sub Application_ThreadException( _
ByVal sender As Object, _
ByVal e As System.Threading.ThreadExceptionEventArgs)
MessageBox.Show( _
"Send the following to support: " & _
e.Exception.ToString())
End Sub


To email log use System.Net.Mail http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx
or 3rd party tools like log4net or Application Blogs,

btw, if your are in the web project u can use Health Monitoring features
http://msdn2.microsoft.com/en-us/library/ms178701.aspx

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

J> Hi Michael
J>
J> Thanks. Is there an example somewhere I can look at as to how to do
J> some comprehensive exception handling with option to email log to the
J> developer?
J>
J> Many Thanks
J>
J> Regards
J>
J> J>
Hello John,

You need to guard against unhandled exceptions by registering a
handler
for them.
Just add a ThreadExceptionEventHandler to the
Application.ThreadException
delegate
---
WBR, Michael Nemtsev [.NET/C# MVP]. My blog:
http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/
"The greatest danger for most of us is not that our aim is too high
and we miss it, but that it is too low and we reach it" (c)
Michelangelo

J> What can I do to improve?
J> J> Thanks
J> J> Regards
J> J>
Hi

My vb.net winform app has frmMyForm as the start-up form. I have
enclosed My.Forms.frmMyForm.Show() within try/catch. Will this do
the trick of handling all exceptions that have not been handled
elsewhere?

Thanks

Regards

Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e
As
Microsoft.VisualBasic.ApplicationServices.StartupEventArgs)
Handles
Me.Startup
Try
My.Forms.frmMyForm.Show()
Catch ex As Exception
' Exception handling here
End Try
End Sub
In terms of preventing the default exception handler from
terminating your app, I guess you could say it would work. In terms
of providing a context sensitive response to a given exception and
giving your application a chance to recover and continue, it's not
going to be useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top