Name of offending code
-
Hi, In an attempt to simplify the debugging process, I wrote a public sub EC (ErrorCatcher), that I can call from anywhere in my app, which writes all necessary information to a text file. Something like:
Public Sub EC(Byval err As Exception) dim line as string = Now & " - Error: " & Err.TargetSite.Name & " - " & Err.Message 'write line to file, etc. End Sub Private Sub MyCode() Try 'some error happens here Catch ex As Exception EC(ex) End Try End Sub
ThisErr.TargetSite.Name
is just my latest attempt, but it does not tell me that the error took place in Private Sub MyCode. Is there any way (other than passing it to the EC sub as a handwritten string) at all to find out in what part of the code the exception occurred, at runtime, and if yes then how? Any help or suggestions appreciated. JohanMy advice is free, and you may get what you paid for.
-
Hi, In an attempt to simplify the debugging process, I wrote a public sub EC (ErrorCatcher), that I can call from anywhere in my app, which writes all necessary information to a text file. Something like:
Public Sub EC(Byval err As Exception) dim line as string = Now & " - Error: " & Err.TargetSite.Name & " - " & Err.Message 'write line to file, etc. End Sub Private Sub MyCode() Try 'some error happens here Catch ex As Exception EC(ex) End Try End Sub
ThisErr.TargetSite.Name
is just my latest attempt, but it does not tell me that the error took place in Private Sub MyCode. Is there any way (other than passing it to the EC sub as a handwritten string) at all to find out in what part of the code the exception occurred, at runtime, and if yes then how? Any help or suggestions appreciated. JohanMy advice is free, and you may get what you paid for.
Yes, you can get the stack trace from the exception object and print it, it will tell you what method threw the exception, and a call stack down from there.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi, In an attempt to simplify the debugging process, I wrote a public sub EC (ErrorCatcher), that I can call from anywhere in my app, which writes all necessary information to a text file. Something like:
Public Sub EC(Byval err As Exception) dim line as string = Now & " - Error: " & Err.TargetSite.Name & " - " & Err.Message 'write line to file, etc. End Sub Private Sub MyCode() Try 'some error happens here Catch ex As Exception EC(ex) End Try End Sub
ThisErr.TargetSite.Name
is just my latest attempt, but it does not tell me that the error took place in Private Sub MyCode. Is there any way (other than passing it to the EC sub as a handwritten string) at all to find out in what part of the code the exception occurred, at runtime, and if yes then how? Any help or suggestions appreciated. JohanMy advice is free, and you may get what you paid for.
I believe you need to check the
StackTrace
property.err.StackTrace
Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
-
Hi, In an attempt to simplify the debugging process, I wrote a public sub EC (ErrorCatcher), that I can call from anywhere in my app, which writes all necessary information to a text file. Something like:
Public Sub EC(Byval err As Exception) dim line as string = Now & " - Error: " & Err.TargetSite.Name & " - " & Err.Message 'write line to file, etc. End Sub Private Sub MyCode() Try 'some error happens here Catch ex As Exception EC(ex) End Try End Sub
ThisErr.TargetSite.Name
is just my latest attempt, but it does not tell me that the error took place in Private Sub MyCode. Is there any way (other than passing it to the EC sub as a handwritten string) at all to find out in what part of the code the exception occurred, at runtime, and if yes then how? Any help or suggestions appreciated. JohanMy advice is free, and you may get what you paid for.
Hi, rather than using Exception.Message and/or Exception.StackTrace you really should use Exception.ToString() it will show you at least the Message and the StackTrace but also: - additional information (e.g. the filepath on a File Not Found) - information about "inner exceptions" :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Hi, rather than using Exception.Message and/or Exception.StackTrace you really should use Exception.ToString() it will show you at least the Message and the StackTrace but also: - additional information (e.g. the filepath on a File Not Found) - information about "inner exceptions" :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
Thanks Luc, I'll definitely give this a try.
My advice is free, and you may get what you paid for.
-
I believe you need to check the
StackTrace
property.err.StackTrace
Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
Thanks Steve, I will try this.
My advice is free, and you may get what you paid for.
-
Yes, you can get the stack trace from the exception object and print it, it will tell you what method threw the exception, and a call stack down from there.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Thanks Christian, Steve also suggested this, and according to Luc I can get even more information out of an exception by simply using Exception.ToString(). Thank all you guys, this really helps.
My advice is free, and you may get what you paid for.