John,
As Göran suggests, check out the Exception.StackTrace property.
http://msdn2.microsoft.com/en-us/lib...tacktrace.aspx
Like every developer, I've got tons of error trapping code that hard code
the name of the function or sub name so I can error log it.
Unlike VB6 & other COM based languages. .NET itself has all the error
trapping code to track the name of functions, subs, properties allowing you
to log rich Exception objects that include stack traces & other contextual
information; such as the Exception.Data collection:
http://msdn2.microsoft.com/en-us/lib...tion.data.aspx
Has anyone found a way thru reflection to get the name of
the currently running fuction/subprocedure name?
Although you can use GetCurrentMethod.Name as (O)enone suggests. Simply
throwing & catch Exception objects avoids needing to know the name of
functions, subs, and properties. Further it avoids needing to code "tons of
error trapping code" to log it. I normally include "pounds, maybe ounces, of
error trapping code" at higher levels that record the entire Exception
object. At lower level, I may include a Try/Catch simply so the Catch can
include further contextual information (such as parameter values) in either
the Exception.Data property or custom properties on custom Exception classes
in the exception that is thrown to the higher levels.
Mostly my lower levels use Try/Finally or the new Using statement ensure
resources (IDisposable objects such as SQL Connection objects & System
Drawing/GDI+ objects) are property disposed of.
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"John Simpson" <Jo*********@discussions.microsoft.comwrote in message
news:D7**********************************@microsof t.com...
Like every developer, I've got tons of error trapping code that hard code
the name of the function or sub name so I can error log it. It seems from
other discussions that the only way to get the function or subprocedure
name
is to either hard code it or to use a Constant to store it and reference
the
Constant in each Catch statement. There are no properties that return the
function/sub name. Has anyone found a way thru reflection to get the name
of
the currently running fuction/subprocedure name?
Thank you so much for your help.