Exception Messaging

pcf108

Freshman
Joined
Sep 19, 2003
Messages
30
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.
 
If you have a windows forms, you can deliver the message through a messagebox for example.
Visual Basic:
MessageBox.Show(ex.Message)

or use the ErrorProvider Control (you can search for help on MSDN for the error provider)


Hope this helps,
 
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.

Code:
  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
 
Back
Top