Method that gets current location in code?

Discussion in 'ASP .Net' started by =?Utf-8?B?TmlyYmhv?=, May 3, 2005.

  1. Hi,

    I'm newish to C# .Net. I'm doing some error handling in my ASP.net pages.

    When handling the error in the catch block, I want to pass through the
    namespace of where the error occured.. something like
    "application.page.method" - I could hardcode this for every ASP.net page, but
    I'm sure there must be something in .Net that gives me this for free.

    Does anyone know of something I could use?

    Cheers!
    =?Utf-8?B?TmlyYmhv?=, May 3, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?TmlyYmhv?=

    Patrice Guest

    AFAIK Exception.ToString has this info. The stack trace could perhaps be
    avialable separately...


    Patrice

    --

    "Nirbho" <> a écrit dans le message de
    news:...
    > Hi,
    >
    > I'm newish to C# .Net. I'm doing some error handling in my ASP.net pages.
    >
    > When handling the error in the catch block, I want to pass through the
    > namespace of where the error occured.. something like
    > "application.page.method" - I could hardcode this for every ASP.net page,

    but
    > I'm sure there must be something in .Net that gives me this for free.
    >
    > Does anyone know of something I could use?
    >
    > Cheers!
    Patrice, May 3, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?TmlyYmhv?=

    Scott Allen Guest

    When a program executes, each method is given a "stack frame" as an
    area for temporary storage. Local variables and a return address to
    the caller are often stored in the stack frame.

    When a method calls a second method, a new stack frame is generated
    for the call. When the second method returns that new stack frame can
    be cleaned up - it's just temporary storage for one method call.

    When there is an exception you can not only tell where you are, but
    where you have been by looking at a 'stack trace'. A stack trace
    examines the active stack frames on the thread to see how you arrived
    at this point.

    You can start digging into stack frames yourself by looking at the
    StackTrace property of an exception.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Tue, 3 May 2005 07:00:14 -0700, Nirbho
    <> wrote:

    >Hi,
    >
    >I'm newish to C# .Net. I'm doing some error handling in my ASP.net pages.
    >
    >When handling the error in the catch block, I want to pass through the
    >namespace of where the error occured.. something like
    >"application.page.method" - I could hardcode this for every ASP.net page, but
    >I'm sure there must be something in .Net that gives me this for free.
    >
    >Does anyone know of something I could use?
    >
    >Cheers!
    Scott Allen, May 3, 2005
    #3
  4. =?Utf-8?B?TmlyYmhv?=

    Brock Allen Guest

    Look into the Exception.TargetSite. Exception.TargetSite.Name is the name
    of the method. Exception.TargetSite.DeclaringType.FullName is the name of
    the containing class.

    OTOH, calling Exception.ToString() will print all this out for you (and more).


    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi,
    >
    > I'm newish to C# .Net. I'm doing some error handling in my ASP.net
    > pages.
    >
    > When handling the error in the catch block, I want to pass through the
    > namespace of where the error occured.. something like
    > "application.page.method" - I could hardcode this for every ASP.net
    > page, but I'm sure there must be something in .Net that gives me this
    > for free.
    >
    > Does anyone know of something I could use?
    >
    > Cheers!
    >
    Brock Allen, May 3, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Mueller
    Replies:
    5
    Views:
    499
    Steven Saunderson
    Jul 10, 2006
  2. Matthew Heidemann
    Replies:
    14
    Views:
    229
    eT Ma
    Mar 22, 2011
  3. John Joyce

    gets gets

    John Joyce, Mar 26, 2007, in forum: Ruby
    Replies:
    2
    Views:
    325
    John Joyce
    Mar 26, 2007
  4. John Joyce

    Return of gets gets

    John Joyce, Apr 23, 2007, in forum: Ruby
    Replies:
    0
    Views:
    173
    John Joyce
    Apr 23, 2007
  5. Replies:
    1
    Views:
    269
    Thomas 'PointedEars' Lahn
    Mar 19, 2008
Loading...

Share This Page