I'm making a library DLL with a standard error handler for all my code. I want to pass the hierarchical structure of the calling sub, for my error handler to post it back to me as a heading. Then when I get a message from my error handler I know exactly where to look without deciphering the nested InnerExceptions and StackTraces. I can manually enter it everytime I make a try/catch statement, but I'd rather it be handled with code to prevent copy/paste omissions. Here is what I got so far.
"MyLibrary.Controls.ctrFieldControl.SetSizes" is the hierarchical structure of the above sub. Caller is the hierarchical structure of the sub that called this one.
Any ideas?
Thanx for your time.
Private Sub SetSizes(ByVal Caller As System.String) Try 'Code to do work Catch ex As Exception ErrorHandler.ErrorMsg(ex, "MyLibrary.Controls.ctrFieldControl.SetSizes", Caller, ErrorHandler.ErrorTitle.CustomControl) End Try End Sub
"MyLibrary.Controls.ctrFieldControl.SetSizes" is the hierarchical structure of the above sub. Caller is the hierarchical structure of the sub that called this one.
Public Class ErrorHandler Overloads Shared Sub ErrorMsg(ByVal ex As System.Exception, ByVal MethodLocation As System.String, ByVal MethodCaller As System.String, ByVal Title As ErrorTitle) Dim strTitle As System.String = "Application" Select Case Title Case ErrorTitle.Application strTitle = "Application Error" Case ErrorTitle.Library strTitle = "Library Error" Case ErrorTitle.CustomControl strTitle = "CustomControl Error" End Select ErrorMsg(ex, MethodLocation, MethodCaller, strTitle) End Sub Overloads Shared Sub ErrorMsg(ByVal ex As System.Exception, ByVal MethodLocation As System.String, ByVal MethodCaller As System.String, ByVal Title As System.String) Dim LF As System.String = Microsoft.VisualBasic.ChrW(10) Dim dLF As System.String = LF & LF Dim Paragraph As System.String = MethodLocation If Strings.Trim(MethodCaller) <> "" Then Paragraph = Paragraph & LF & MethodCaller If ex.InnerException Is Nothing Then Paragraph = (Paragraph & dLF & ex.Message.ToString) Else If ex.InnerException.InnerException Is Nothing Then Paragraph = (Paragraph & dLF & ex.Message.ToString & dLF & ex.InnerException.ToString) Else If ex.InnerException.InnerException.InnerException Is Nothing Then Paragraph = (Paragraph & dLF & ex.Message.ToString & dLF & ex.InnerException.ToString & dLF & ex.InnerException.InnerException.ToString) Else Paragraph = (Paragraph & dLF & ex.Message.ToString & dLF & ex.InnerException.ToString & dLF & ex.InnerException.InnerException.ToString & dLF & ex.InnerException.InnerException.ToString) End If End If End If If Strings.Left(Paragraph, 2) = dLF Then Paragraph = Strings.Right(Paragraph, (Strings.Len(Paragraph) - 2)) MsgBox(Paragraph, MsgBoxStyle.OkOnly, Title) End Sub Public Enum ErrorTitle As Integer Application = 0 Library = 1 CustomControl = 2 End Enum End Class
Any ideas?
Thanx for your time.
Last edited: