Posted By

mafro on 05/08/09


Tagged

exception


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

haoji


Handle Unhandled Exceptions


 / Published in: VB.NET
 

Event handling for exceptions in .NET. Very useful for background reporting and informing the user in a friendly way. Stack trace displays line numbers!

  1. 'create unhandled exception handler
  2. AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf ucLinker_UnhandledExceptionHandler
  3.  
  4. 'event handler
  5. Private Sub uc_UnhandledExceptionHandler(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
  6. Dim ex As Exception = DirectCast(e.ExceptionObject, Exception)
  7.  
  8. Dim sb As New System.Text.StringBuilder()
  9. sb.AppendLine("************** Exception Text **************")
  10. sb.Append(ex.GetType.ToString)
  11. sb.Append(": ")
  12. sb.AppendLine(ex.Message)
  13. sb.Append(ex.StackTrace)
  14.  
  15. Console.WriteLine(sb.ToString)
  16. End Sub

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: mamali_x on August 2, 2009

http://daringfireball.net/projects/markdown/dingus

You need to login to post a comment.