Long waited attempt to handle exceptions properly.

Discussion in 'ASP .Net' started by Guest, Nov 12, 2003.

  1. Guest

    Guest Guest

    Unfortunately I've used exception handling as a debugging tool.
    Now I want to be smarter about handling errors. Today in the global.asx in the Application_OnError event, I inserted code to email me the Server.GetLastError with some other information.
    Everythings working fine, but the information about the last error isn't useful. I stilll have to step through the program (VS.NET 2003) to find exactly where the error(s) originate.

    Tell me if this is right.

    1. The Code Behind uses and Object (dll).

    2. Object uses another Data Access Object to retrieve data.

    Here I know SQLException is being raised because I purposely changed the connect string.

    I have no try catch blocks.

    So......

    If I throw Exceptions from the Data Access Object and the Code behind......will I receive more info about the error.

    I'll give more detailed info...if needed, but someone with experience should know what I'm talking about.


    While I'm testing myself.....I like hearing peoples opinions.

    Thanks,
    Lee
     
    Guest, Nov 12, 2003
    #1
    1. Advertising

  2. Guest

    Alvin Bruney Guest

    the further away from the exception you catch it, the less likely you are to
    have its context. catching errors at the global level is a last resort move.
    you should try to catch at the page level before global. you should be
    wrapping code with try catch blocks where you expect errors may occur so you
    can handle them at this point and continue.

    You may be able to glean more information from the Error property of the
    Context object which returns the first exception object accumulated during
    http processing.

    regards

    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    <> wrote in message
    news:...
    > Unfortunately I've used exception handling as a debugging tool.
    > Now I want to be smarter about handling errors. Today in the global.asx

    in the Application_OnError event, I inserted code to email me the
    Server.GetLastError with some other information.
    > Everythings working fine, but the information about the last error isn't

    useful. I stilll have to step through the program (VS.NET 2003) to find
    exactly where the error(s) originate.
    >
    > Tell me if this is right.
    >
    > 1. The Code Behind uses and Object (dll).
    >
    > 2. Object uses another Data Access Object to retrieve data.
    >
    > Here I know SQLException is being raised because I purposely changed the

    connect string.
    >
    > I have no try catch blocks.
    >
    > So......
    >
    > If I throw Exceptions from the Data Access Object and the Code

    behind......will I receive more info about the error.
    >
    > I'll give more detailed info...if needed, but someone with experience

    should know what I'm talking about.
    >
    >
    > While I'm testing myself.....I like hearing peoples opinions.
    >
    > Thanks,
    > Lee
    >
    >
    >
    >
     
    Alvin Bruney, Nov 12, 2003
    #2
    1. Advertising

  3. Guest

    Natty Gur Guest

    Hi,

    The innerExcaption property is holding the sql excaption data that
    you're looking after.

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Natty Gur, Nov 12, 2003
    #3
  4. You could add additional info to each catch like this

    catch(Exception eX)
    {
    string sErr = "Error in blah.aspx, SomeFunction() " + eX.Message;
    SendError(sErr);
    }

    plus any other relevent info so you know what file and what function
    threw the error.


    http://www.studentshopper.com/
     
    isaac nicolay, Nov 12, 2003
    #4
  5. Guest

    Guest Guest

    Thank you.....one more ...Re: Long waited attempt to handle exceptions properly.

    Thank you,

    I need to improve my developing of systems. Along with
    commenting code, handling exceptions seemed be something
    I only used while in debug mode.


    If I catch an error before the last line of defense, most
    of the time it's just to log the info and then I (by
    habit) just throw a new exception with some additional
    message.

    If I just throw exceptions up the stack.....Is that
    additional information going to appear at the global
    level ?

    I'm also looking for other uses besides logging and
    sending messages. Or is that the primary use ?

    >-----Original Message-----
    >the further away from the exception you catch it, the

    less likely you are to
    >have its context. catching errors at the global level is

    a last resort move.
    >you should try to catch at the page level before global.

    you should be
    >wrapping code with try catch blocks where you expect

    errors may occur so you
    >can handle them at this point and continue.
    >
    >You may be able to glean more information from the Error

    property of the
    >Context object which returns the first exception object

    accumulated during
    >http processing.
    >
    >regards
    >
    >--
    >
    >
    >-----------
    >Got TidBits?
    >Get it here: www.networkip.net/tidbits
    ><> wrote in message
    >news:...
    >> Unfortunately I've used exception handling as a

    debugging tool.
    >> Now I want to be smarter about handling errors.

    Today in the global.asx
    >in the Application_OnError event, I inserted code to

    email me the
    >Server.GetLastError with some other information.
    >> Everythings working fine, but the information about

    the last error isn't
    >useful. I stilll have to step through the program

    (VS.NET 2003) to find
    >exactly where the error(s) originate.
    >>
    >> Tell me if this is right.
    >>
    >> 1. The Code Behind uses and Object (dll).
    >>
    >> 2. Object uses another Data Access Object to retrieve

    data.
    >>
    >> Here I know SQLException is being raised because I

    purposely changed the
    >connect string.
    >>
    >> I have no try catch blocks.
    >>
    >> So......
    >>
    >> If I throw Exceptions from the Data Access Object and

    the Code
    >behind......will I receive more info about the error.
    >>
    >> I'll give more detailed info...if needed, but someone

    with experience
    >should know what I'm talking about.
    >>
    >>
    >> While I'm testing myself.....I like hearing peoples

    opinions.
    >>
    >> Thanks,
    >> Lee
    >>
    >>
    >>
    >>

    >
    >
    >.
    >
     
    Guest, Nov 14, 2003
    #5
  6. Guest

    Alvin Bruney Guest

    Re: Thank you.....one more ...Re: Long waited attempt to handle exceptions properly.

    The primary reason for rethrowing an exception is to interpret the catched
    exception and interpret it as your own (add or retract information from it).
    One gotcha is that when you rethrow, the run-time now only knows the point
    of origin at the rethrow line. It doesn't know that the exception came from
    deeper in the code so the rethrow becomes the point of origin. However, if
    you append information from the original exception you can work around this.

    There are lots of other uses, for example, you can redirect back to the
    calling page so that the page starts over again automatically after a
    critical error.
    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    <> wrote in message
    news:5a9301c3aac1$91362280$...
    > Thank you,
    >
    > I need to improve my developing of systems. Along with
    > commenting code, handling exceptions seemed be something
    > I only used while in debug mode.
    >
    >
    > If I catch an error before the last line of defense, most
    > of the time it's just to log the info and then I (by
    > habit) just throw a new exception with some additional
    > message.
    >
    > If I just throw exceptions up the stack.....Is that
    > additional information going to appear at the global
    > level ?
    >
    > I'm also looking for other uses besides logging and
    > sending messages. Or is that the primary use ?
    >
    > >-----Original Message-----
    > >the further away from the exception you catch it, the

    > less likely you are to
    > >have its context. catching errors at the global level is

    > a last resort move.
    > >you should try to catch at the page level before global.

    > you should be
    > >wrapping code with try catch blocks where you expect

    > errors may occur so you
    > >can handle them at this point and continue.
    > >
    > >You may be able to glean more information from the Error

    > property of the
    > >Context object which returns the first exception object

    > accumulated during
    > >http processing.
    > >
    > >regards
    > >
    > >--
    > >
    > >
    > >-----------
    > >Got TidBits?
    > >Get it here: www.networkip.net/tidbits
    > ><> wrote in message
    > >news:...
    > >> Unfortunately I've used exception handling as a

    > debugging tool.
    > >> Now I want to be smarter about handling errors.

    > Today in the global.asx
    > >in the Application_OnError event, I inserted code to

    > email me the
    > >Server.GetLastError with some other information.
    > >> Everythings working fine, but the information about

    > the last error isn't
    > >useful. I stilll have to step through the program

    > (VS.NET 2003) to find
    > >exactly where the error(s) originate.
    > >>
    > >> Tell me if this is right.
    > >>
    > >> 1. The Code Behind uses and Object (dll).
    > >>
    > >> 2. Object uses another Data Access Object to retrieve

    > data.
    > >>
    > >> Here I know SQLException is being raised because I

    > purposely changed the
    > >connect string.
    > >>
    > >> I have no try catch blocks.
    > >>
    > >> So......
    > >>
    > >> If I throw Exceptions from the Data Access Object and

    > the Code
    > >behind......will I receive more info about the error.
    > >>
    > >> I'll give more detailed info...if needed, but someone

    > with experience
    > >should know what I'm talking about.
    > >>
    > >>
    > >> While I'm testing myself.....I like hearing peoples

    > opinions.
    > >>
    > >> Thanks,
    > >> Lee
    > >>
    > >>
    > >>
    > >>

    > >
    > >
    > >.
    > >
     
    Alvin Bruney, Nov 15, 2003
    #6
    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. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    725
    Eric Sosman
    Jul 8, 2003
  2. Daniel Rudy

    unsigned long long int to long double

    Daniel Rudy, Sep 19, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,232
    Peter Shaggy Haywood
    Sep 20, 2005
  3. Mathieu Dutour

    long long and long

    Mathieu Dutour, Jul 17, 2007, in forum: C Programming
    Replies:
    4
    Views:
    505
    santosh
    Jul 24, 2007
  4. Bart C

    Use of Long and Long Long

    Bart C, Jan 9, 2008, in forum: C Programming
    Replies:
    27
    Views:
    837
    Peter Nilsson
    Jan 15, 2008
  5. GMI
    Replies:
    3
    Views:
    530
    Tad McClellan
    Jun 19, 2005
Loading...

Share This Page