|
-
Aug 18th, 2005, 08:13 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Global Error Handler
Hi All.
I want to create like a global error handler.
Whereever an error in code appears, I want it to open a form. (FrmErrorHandler) Then in this form, it should put the error in a textbox.
This I then want to save with a few other variables (app version, workstation, username etc etc) in my sql server.
The only thing the user needs to see, is the form that tells him that an error occurred (almost like that anoying send / don't send forms of windows xp)
How do I say for it to open the form no matter what the error is (sql server, my application, user input)
How do I insert the error code, in the form?
Thanks
Rudi
-
Aug 18th, 2005, 08:44 AM
#2
Hyperactive Member
Re: Global Error Handler
To handle any application error I add a handler for the Application.ThreadException in my startup routines as follows
AddHandler Application.ThreadException, AddressOf ApplicationException
Private Sub ApplicationException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
ErrorMsg(e.Exception)
End Sub
Note that I would still highty recommend using Try, Catch, Finally, End Try where you are likely to come across errors, such as when connecting to a database. Relying on the Application.ThreadException to deal with and handle your exceptions is a very bad idea!
If you create a global Function ErrorMsg(ByVal e as Exception)
Then you can have your function do what you want, ie. insert the error into a SQL database.
Hope this helps
-
Aug 18th, 2005, 08:52 AM
#3
Thread Starter
Addicted Member
Re: Global Error Handler
Hey Mr Duck....
I think I'll go the global Module route....
What kind of code would I have to add to each form to capture these errors? I mean, what code would I need to add to forms to run the module?
And do you have and sample code or examples to give ideas?
Thanks
Rudi
-
Aug 18th, 2005, 09:12 AM
#4
Hyperactive Member
Re: Global Error Handler
Say you wanted to capture any unhandled errors in your Form myForm
You could use something like the following
VB Code:
Try
Dim frm AS new myForm()
frm.ShowDialog()
Catch ex As Exception
ErrorMsg(ex)
End Try
where you have ErrorMsg defined as
VB Code:
Public Sub ErrorMsg(ByVal ex AS Exception)
MessageBox.Show("Error! " & ex.ToString)
End Sub
-
Aug 18th, 2005, 09:23 AM
#5
Thread Starter
Addicted Member
Re: Global Error Handler
I was actually speaking of opening a form... but ok I got the idea, thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|