Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Module ExHandler
- ''' <summary>
- ''' Option for how to handle the exception
- ''' </summary>
- ''' <remarks>
- ''' No LogAndExit since it would be considered as a crash
- ''' Check MSDN for FlagsAttribute
- ''' </remarks>
- <FlagsAttribute()> _
- Public Enum ExOption
- ''' <summary>
- ''' Log the message to a default log file
- ''' </summary>
- ''' <remarks></remarks>
- Log = 1
- ''' <summary>
- ''' Display the message in a dialog box
- ''' </summary>
- ''' <remarks></remarks>
- Display = 2
- LogAndDisplay = Log Or Display
- ''' <summary>
- ''' Kill the application
- ''' </summary>
- ''' <remarks></remarks>
- ExitApp = 4
- DisplayAndExit = Display Or ExitApp
- LogAndDisplayAndExit = Log Or Display Or ExitApp
- End Enum
- 'if you provide nothing for ExtraMsg_ToBe_LogAndShow, only the exception message will be displayed and logged
- ''' <summary>
- ''' Handle the exception provided and multiple ways
- ''' </summary>
- ''' <param name="e">The exception to handle</param>
- ''' <param name="ExtraMsg_ToBe_LogAndShow">Extra message if not provided only exception description will be displayed instead</param>
- ''' <param name="Action">Default is to just log</param>
- ''' <remarks></remarks>
- Public Sub HandleEx(ByVal e As Exception, _
- Optional ByVal ExtraMsg_ToBe_LogAndShow As String = "", _
- Optional ByVal Action As ExHandler.ExOption = ExOption.Log)
- 'Log The custom message to both log files
- 'But exception message only to detailed one
- If Action And ExOption.Log Then
- If ExtraMsg_ToBe_LogAndShow.Length > 0 Then
- Log(ExtraMsg_ToBe_LogAndShow)
- LogSummary(ExtraMsg_ToBe_LogAndShow)
- End If
- Log(e.ToString)
- End If
- 'Display Custom message or exception message
- If Action And ExOption.Display Then
- If ExtraMsg_ToBe_LogAndShow.Length > 0 Then
- ErrMsg(ExtraMsg_ToBe_LogAndShow)
- #If DEBUG Then
- ErrMsg(e.ToString)
- #End If
- Else
- ErrMsg(e.ToString)
- End If
- End If
- If Action And ExOption.ExitApp Then
- Environment.Exit(1)
- End If
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment