Is there a way to display the name of the routine where an error occurs in my code using the framework Obviously, I could put the name of each routine in a message and so forth but that is just a bad design. I was hoping that I would be able to use Reflection or Exception handling to do this in a structured way.
I have several applications that are monitored by IT professionals internal to the company who need as much information as possible about an error that occurs when support is not immediately available. Also there are reporting considerations for tracking the errors.

Displaying the procedure or sub where a error occurs to a user.
Carlos Hdez
The following example may help.
Create a console application and paste this code in.
Module Module1
Sub Main()
Foo.xyz()
End Sub
End Module
Public Module Foo
Public Sub xyz()
Try
Throw New Exception("ffff")
Catch ex As Exception
MsgBox(ex.TargetSite.ReflectedType.FullName.ToString & " Function:" & ex.TargetSite.Name.ToString)
End Try
End Sub
End Module
Chrisql
I alway do my messageboxes like this:
Try
code......
catch e as exception
msgbox("Exception" & e.message,MsgBoxStyle.Information,"ReadRow - I/O Error")
End Try....
Where the routine name is ReadRow
Pat Backowski
Also check out the Application.ThreadException event.
and Exception.StackTrace
jornjorn
(source code with test app here)
I have this component I put on my main forms to trap all unhandled errors using the Application.ThreadException event-
1.1 code but it compiles in 2.0
create a new class library project call it ErrorTrap.
add references to System Windows.Forms and System.Drawing
add a new form called error form put this code in it (again this is 1.1 code - download the source and convert for 2.0)
you can add ExceptionHandler to your toolbox and drop it on your main form to trap all unhandled errors. It displays the Message as well as detailed Exception information - TargetSite and Stack trace.
source code with test app here
theprogrammer
programmatically
Try
code.....
catch e as exception
msgbox("Exception: " & e.message, MsgBoxStyle.Information, Function())
End Try...