PikachuEXE

Test

Jun 7th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.37 KB | None | 0 0
  1. Public Module ExHandler
  2.  
  3.     ''' <summary>
  4.     ''' Option for how to handle the exception
  5.     ''' </summary>
  6.     ''' <remarks>
  7.     ''' No LogAndExit since it would be considered as a crash
  8.     ''' Check MSDN for FlagsAttribute
  9.     ''' </remarks>
  10.     <FlagsAttribute()> _
  11.     Public Enum ExOption
  12.         ''' <summary>
  13.         ''' Log the message to a default log file
  14.         ''' </summary>
  15.         ''' <remarks></remarks>
  16.         Log = 1
  17.         ''' <summary>
  18.         ''' Display the message in a dialog box
  19.         ''' </summary>
  20.         ''' <remarks></remarks>
  21.         Display = 2
  22.         LogAndDisplay = Log Or Display
  23.         ''' <summary>
  24.         ''' Kill the application
  25.         ''' </summary>
  26.         ''' <remarks></remarks>
  27.         ExitApp = 4
  28.         DisplayAndExit = Display Or ExitApp
  29.         LogAndDisplayAndExit = Log Or Display Or ExitApp
  30.     End Enum
  31.  
  32.     'if you provide nothing for ExtraMsg_ToBe_LogAndShow, only the exception message will be displayed and logged
  33.     ''' <summary>
  34.     ''' Handle the exception provided and multiple ways
  35.     ''' </summary>
  36.     ''' <param name="e">The exception to handle</param>
  37.     ''' <param name="ExtraMsg_ToBe_LogAndShow">Extra message if not provided only exception description will be displayed instead</param>
  38.     ''' <param name="Action">Default is to just log</param>
  39.     ''' <remarks></remarks>
  40.     Public Sub HandleEx(ByVal e As Exception, _
  41.         Optional ByVal ExtraMsg_ToBe_LogAndShow As String = "", _
  42.         Optional ByVal Action As ExHandler.ExOption = ExOption.Log)
  43.  
  44.         'Log The custom message to both log files
  45.         'But exception message only to detailed one
  46.         If Action And ExOption.Log Then
  47.             If ExtraMsg_ToBe_LogAndShow.Length > 0 Then
  48.                 Log(ExtraMsg_ToBe_LogAndShow)
  49.                 LogSummary(ExtraMsg_ToBe_LogAndShow)
  50.             End If
  51.             Log(e.ToString)
  52.         End If
  53.  
  54.         'Display Custom message or exception message
  55.         If Action And ExOption.Display Then
  56.             If ExtraMsg_ToBe_LogAndShow.Length > 0 Then
  57.                 ErrMsg(ExtraMsg_ToBe_LogAndShow)
  58. #If DEBUG Then
  59.                 ErrMsg(e.ToString)
  60. #End If
  61.             Else
  62.                 ErrMsg(e.ToString)
  63.             End If
  64.         End If
  65.  
  66.         If Action And ExOption.ExitApp Then
  67.             Environment.Exit(1)
  68.         End If
  69.  
  70.     End Sub
  71. End Module
Advertisement
Add Comment
Please, Sign In to add comment