pcf108 Posted December 8, 2003 Posted December 8, 2003 I'm writing some code to better deliver error messages to users, I was wondering if anyone might have some source that they think might work well for delivering information from exceptions from try and catch. I've been using the console to catch the errors in development, but this isn't very useful to the user. If anyone could help it'd be cool. If not, I'll survive. Quote
Mehyar Posted December 8, 2003 Posted December 8, 2003 If you have a windows forms, you can deliver the message through a messagebox for example. MessageBox.Show(ex.Message) or use the ErrorProvider Control (you can search for help on MSDN for the error provider) Hope this helps, Quote Dream as if you'll live forever, live as if you'll die today
pcf108 Posted December 8, 2003 Author Posted December 8, 2003 I'll check out the ErrorProvider control... Thanks. Quote
Grimfort Posted December 8, 2003 Posted December 8, 2003 Heres a snippet of code that traps any errors running on the application thread. It does let some by (sub threads of other threads) but gets most. Dim eh As CustomExceptionHandler = New CustomExceptionHandler() ' Adds the event handler to the event. AddHandler Application.ThreadException, AddressOf eh.OnThreadException ' Creates a class to handle the exception event. Private Class CustomExceptionHandler ' Handles the exception event. Public Sub OnThreadException(ByVal sender As Object, ByVal t As System.Threading.ThreadExceptionEventArgs) Dim result As DialogResult = System.Windows.Forms.DialogResult.Cancel Try result = Me.ShowThreadExceptionDialog(t.Exception) Catch Try MessageBox.Show("Fatal Error", "Fatal Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop) Finally Application.Exit() End Try End Try ' Exits the program when the user clicks Abort. If (result = System.Windows.Forms.DialogResult.Abort) Then Application.Exit() End If End Sub ' Creates the error message and displays it. Private Function ShowThreadExceptionDialog(ByVal e As Exception) As DialogResult Dim errorMsg As String = "An error occurred please contact the administrator with the following information:" & vbCrLf & vbCrLf errorMsg &= e.Message & vbCrLf errorMsg &= "Stack Trace:" & vbCrLf errorMsg &= e.StackTrace & vbCrLf Return MessageBox.Show(errorMsg, "Application Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop) End Function End Class Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.