Brad Pears wrote:
I am developing a simple error message class and would like the be able to
generate as part of the message the curent class/module/form and function or
sub that the error was generated in without having to hardcode this info to
be passed to the error message class.
System.Reflection.MethodBase.GetCurrentMethod().Na me
gets you the name of the currently executing method, but you have to
code it into every method. Tedious.
I can get the stack trace using system.environment.stacktrace
- but this is too much info.
You /can/ get the StackTrace and pull it to pieces to extract the bit(s)
you're after. You might add this to the constructor (Sub New) of your
"error message class":
Dim sf As System.Diagnostics.StackFrame _
= New System.Diagnostics.StackFrame(1, False)
Dim method As System.Reflection.MethodBase _
= sf.GetMethod()
? method.ReflectedType.FullName
? method.Name
I just want to display the function/sub name where the error was generated
and the parent name of that sub/function
IMHO, if you're using this to track down errors, then you /need/ the
/entire/ stack trace (and more). The logging class I use gets laced
into each and every method and is used to record the entry and exit
points of those methods, complete with arguments and return values.
Without /all/ of this, it's .. rather difficult, shall we say .. to get
to the bottom of what's going wrong.
HTH,
Phill W.