Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Identifying function name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AA2e72E - 07 Sep 2007 08:20 GMT
Is there some generic property that will give me the name of a function
within its catch block?
Jon Skeet [C# MVP] - 07 Sep 2007 08:47 GMT
> 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
Mark Rae [MVP] - 09 Sep 2007 00:28 GMT
>> 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.

What about this: ?
http://msdn2.microsoft.com/en-us/library/system.reflection.methodbase.getcurrent
method.aspx


Are there any performance issues with that...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Arne Vajhøj - 09 Sep 2007 00:42 GMT
>>> Is there some generic property that will give me the name of a function
>>> within its catch block?
[quoted text clipped - 6 lines]
>
> Are there any performance issues with that...?

It is in System.Slow namespace, so with sufficient many calls
it could be a performance problem.

It is probably faster than StackTrace though.

Arne
Arne Vajhøj - 17 Sep 2007 01:16 GMT
>>>> Is there some generic property that will give me the name of a function
>>>> within its catch block?
[quoted text clipped - 11 lines]
>
> 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
Jon Skeet [C# MVP] - 09 Sep 2007 07:12 GMT
> What about this: ?
> http://msdn2.microsoft.com/en-us/library/system.reflection.methodbase
> .getcurrentmethod.aspx
>
> Are there any performance issues with that...?

Not sure, to be honest - I only didn't mention it because I missed it
:)

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Arne Vajhøj - 08 Sep 2007 23:48 GMT
> 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
AA2e72E - 12 Sep 2007 15:00 GMT
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.

> > Is there some generic property that will give me the name of a function
> > within its catch block?
[quoted text clipped - 4 lines]
>
> Arne
Arne Vajhøj - 17 Sep 2007 01:16 GMT
>>> 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)
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.