Identifying function name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there some generic property that will give me the name of a function
within its catch block?
 
Is there some generic property that will give me the name of a function
within its catch block?

You can use the StackTrace class - but don't start building stack
traces in performance critical code.

If you're interested in what threw the exception, you can just use
Exception.TargetSite.

Jon
 
AA2e72E said:
Is there some generic property that will give me the name of a function
within its catch block?

What are you trying to accomplish ?

(when you write the code you know the function name)

Arne
 
I have a single error reporting method that takes the exception variable as
its argument; so I don't know which method caused the exception but as
detailes in the Jon Skeet's post, the exception variable holds the name.
 
Arne said:
It is in System.Slow namespace, so with sufficient many calls
it could be a performance problem.

It is probably faster than StackTrace though.

I made a small test with:
StackTrace
GetCurrentMethod
maintaining a special call stack via AspectDNG

The timings were:

StackTrace: 10,53125
GetCurrentMethod: 2,171875
AOP: 4,171875

So GetCurrentMethod is absolutely the fastest.

But I would say its usability is limited because it does exactly
what its name says so it can only be used in inline code not
out in a special log/whatever method.

Arne
 
AA2e72E said:
I have a single error reporting method that takes the exception variable as
its argument; so I don't know which method caused the exception but as
detailes in the Jon Skeet's post, the exception variable holds the name.

Yes. And because you already have the exception, then there are
very little overhead.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top