Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.37 KB | None | 0 0
  1. Module PublicFuncs
  2.  
  3.     <Runtime.InteropServices.ComVisible(False)>
  4.     Public Sub PushTheStack(ByVal ex As Exception) ':)
  5.         Dim Result As String = String.Empty
  6.         Dim hr As Integer = Runtime.InteropServices.Marshal.GetHRForException(ex)
  7.         'debug normal:
  8.         Result = ex.GetType.ToString & "(0x" & hr.ToString("X8") & "): " & ex.Message & Environment.NewLine & ex.StackTrace & Environment.NewLine
  9.  
  10.         Dim st As StackTrace = New StackTrace(ex, True)
  11.         For Each sf As StackFrame In st.GetFrames
  12.             If sf.GetFileLineNumber() > 0 Then
  13.                 Result &= "Linha número " & sf.GetFileLineNumber() & " no ficheiro: `" & IO.Path.GetFileNameWithoutExtension(sf.GetFileName) & "´ com o método `" & IO.Path.GetFileNameWithoutExtension(sf.GetMethod.Name) & "´ provocou um erro: "
  14.             End If
  15.         Next
  16.         writeDebug("TRACE: " & Result & ex.Message)
  17.  
  18.     End Sub
  19.  
  20.     <Runtime.InteropServices.ComVisible(False)> _
  21.     Public Sub writeDebug(ByVal __text As String)
  22.         Try
  23.             Console.WriteLine(__text)
  24.             Dim objWriter As New System.IO.StreamWriter(Today.ToString("yyyy-MM-dd") & ".log", True)
  25.             objWriter.WriteLine(Now.ToString("yyyy-MM-dd HH:mm:ss") & vbTab & __text)
  26.             objWriter.Close()
  27.         Catch ex As Exception
  28.             '
  29.         End Try
  30.     End Sub
  31. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement