Error Handleing at the Application Level Server Error

Discussion in 'ASP .Net' started by David Lozzi, Jul 20, 2006.

  1. David Lozzi

    David Lozzi Guest

    Howdy,

    I found a nice little book called ASP.NET 2.0 Cookbook by Michael A Kittel
    and Geoffrey LeBlond. Anyway, they have some instructions on how to setup
    application level error handling. Most of my functions have try..catch to
    email me about an error, then I want the application level to fire off to
    send the user to a custom page AND log it in the app log. When an error
    occurs on my page, i get a server error

    Server Error in '/newcart' Application.
    --------------------------------------------------------------------------------

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code. Exception Details:
    System.NullReferenceException: Object reference not set to an instance of an
    object.Source Error: Line 4:
    Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Error
    Line 6: Throw Server.GetLastError()
    Line 7: End Sub
    Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb Line:
    6 Any ideas?Also, I'm under the impression that if an actual error occurs,
    it will not send me to the error page as specified b/c I'm on my development
    machine. is that correct?Thanks!!-- David
    Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com
    David Lozzi, Jul 20, 2006
    #1
    1. Advertising

  2. David,
    You shouldn't have to rethrow the sever last error in your page_error
    event. As long as you don't call Server.ClearError() the Application_Error
    event should still fire and redirection to the error page should occur as
    defined in your web.config.

    Incidentally, I normally use the Page_Error event to perform page state
    clean up and the Application_Error event in the global.asax for custom error
    handling (such as calling an EntLib exception policy - which could you caould
    configure to do your emailing and logging functions).

    Depending on the deployment I sometimes use a custom HTTPModule for hooking
    in to application events. If I want to change how I'm handling an
    application error then I cna change and redeploy th HTTPModule dll rather
    than playing with the global.asax.

    Hope this helps,
    Garth

    "David Lozzi" wrote:

    > Howdy,
    >
    > I found a nice little book called ASP.NET 2.0 Cookbook by Michael A Kittel
    > and Geoffrey LeBlond. Anyway, they have some instructions on how to setup
    > application level error handling. Most of my functions have try..catch to
    > email me about an error, then I want the application level to fire off to
    > send the user to a custom page AND log it in the app log. When an error
    > occurs on my page, i get a server error
    >
    > Server Error in '/newcart' Application.
    > --------------------------------------------------------------------------------
    >
    > Object reference not set to an instance of an object.
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about the error and where it originated in the code. Exception Details:
    > System.NullReferenceException: Object reference not set to an instance of an
    > object.Source Error: Line 4:
    > Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Error
    > Line 6: Throw Server.GetLastError()
    > Line 7: End Sub
    > Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb Line:
    > 6 Any ideas?Also, I'm under the impression that if an actual error occurs,
    > it will not send me to the error page as specified b/c I'm on my development
    > machine. is that correct?Thanks!!-- David
    > Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com
    >
    >
    >
    >
    =?Utf-8?B?R2FydGhT?=, Jul 20, 2006
    #2
    1. Advertising

  3. David Lozzi

    David Lozzi Guest

    The book states to "rethrow the last exception that occured...we do this
    step to avoid having the exception information wrapped with an
    HttpUnhandledException exception. ASP.NET automatically creates a new
    HttpUnhandledException at the page level unless you rethrow the last
    exception." sooo.....

    --
    David Lozzi
    dlozzi@(remove)delphi-ts.com
    www.delphi-ts.com


    "GarthS" <> wrote in message
    news:...
    > David,
    > You shouldn't have to rethrow the sever last error in your page_error
    > event. As long as you don't call Server.ClearError() the
    > Application_Error
    > event should still fire and redirection to the error page should occur as
    > defined in your web.config.
    >
    > Incidentally, I normally use the Page_Error event to perform page state
    > clean up and the Application_Error event in the global.asax for custom
    > error
    > handling (such as calling an EntLib exception policy - which could you
    > caould
    > configure to do your emailing and logging functions).
    >
    > Depending on the deployment I sometimes use a custom HTTPModule for
    > hooking
    > in to application events. If I want to change how I'm handling an
    > application error then I cna change and redeploy th HTTPModule dll rather
    > than playing with the global.asax.
    >
    > Hope this helps,
    > Garth
    >
    > "David Lozzi" wrote:
    >
    >> Howdy,
    >>
    >> I found a nice little book called ASP.NET 2.0 Cookbook by Michael A
    >> Kittel
    >> and Geoffrey LeBlond. Anyway, they have some instructions on how to setup
    >> application level error handling. Most of my functions have try..catch to
    >> email me about an error, then I want the application level to fire off to
    >> send the user to a custom page AND log it in the app log. When an error
    >> occurs on my page, i get a server error
    >>
    >> Server Error in '/newcart' Application.
    >> --------------------------------------------------------------------------------
    >>
    >> Object reference not set to an instance of an object.
    >> Description: An unhandled exception occurred during the execution of the
    >> current web request. Please review the stack trace for more information
    >> about the error and where it originated in the code. Exception Details:
    >> System.NullReferenceException: Object reference not set to an instance of
    >> an
    >> object.Source Error: Line 4:
    >> Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Me.Error
    >> Line 6: Throw Server.GetLastError()
    >> Line 7: End Sub
    >> Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb
    >> Line:
    >> 6 Any ideas?Also, I'm under the impression that if an actual error
    >> occurs,
    >> it will not send me to the error page as specified b/c I'm on my
    >> development
    >> machine. is that correct?Thanks!!-- David
    >> Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com
    >>
    >>
    >>
    >>
    David Lozzi, Jul 20, 2006
    #3
  4. David,
    I ran a quick test and had no problem throwing the Server.GetLastError
    within the Page_Error, redirection to the error page occured as expected.
    I'll ask a question, and I hope I don't offend ;), have you set the mode of
    your customErrors section to 'On'?
    eg:
    <customErrors defaultRedirect="~/Error.aspx" mode="On">
    </customErrors>

    If the mode is Off or RemoteOnly on your development machine you'll get the
    standard server error.

    As an aside, I don't normally mind the exceptions being wrapped in an
    HttpUnhandledException. You can get the original exception from the
    InnerException property of the unhandled exception in the application_error
    event. I guess a down side (or up side depending on how you look at it) to
    this is that HttpUnhandledExceptions are logged in the Application log on the
    server.

    Garth.


    "David Lozzi" wrote:

    > The book states to "rethrow the last exception that occured...we do this
    > step to avoid having the exception information wrapped with an
    > HttpUnhandledException exception. ASP.NET automatically creates a new
    > HttpUnhandledException at the page level unless you rethrow the last
    > exception." sooo.....
    >
    > --
    > David Lozzi
    > dlozzi@(remove)delphi-ts.com
    > www.delphi-ts.com
    >
    >
    > "GarthS" <> wrote in message
    > news:...
    > > David,
    > > You shouldn't have to rethrow the sever last error in your page_error
    > > event. As long as you don't call Server.ClearError() the
    > > Application_Error
    > > event should still fire and redirection to the error page should occur as
    > > defined in your web.config.
    > >
    > > Incidentally, I normally use the Page_Error event to perform page state
    > > clean up and the Application_Error event in the global.asax for custom
    > > error
    > > handling (such as calling an EntLib exception policy - which could you
    > > caould
    > > configure to do your emailing and logging functions).
    > >
    > > Depending on the deployment I sometimes use a custom HTTPModule for
    > > hooking
    > > in to application events. If I want to change how I'm handling an
    > > application error then I cna change and redeploy th HTTPModule dll rather
    > > than playing with the global.asax.
    > >
    > > Hope this helps,
    > > Garth
    > >
    > > "David Lozzi" wrote:
    > >
    > >> Howdy,
    > >>
    > >> I found a nice little book called ASP.NET 2.0 Cookbook by Michael A
    > >> Kittel
    > >> and Geoffrey LeBlond. Anyway, they have some instructions on how to setup
    > >> application level error handling. Most of my functions have try..catch to
    > >> email me about an error, then I want the application level to fire off to
    > >> send the user to a custom page AND log it in the app log. When an error
    > >> occurs on my page, i get a server error
    > >>
    > >> Server Error in '/newcart' Application.
    > >> --------------------------------------------------------------------------------
    > >>
    > >> Object reference not set to an instance of an object.
    > >> Description: An unhandled exception occurred during the execution of the
    > >> current web request. Please review the stack trace for more information
    > >> about the error and where it originated in the code. Exception Details:
    > >> System.NullReferenceException: Object reference not set to an instance of
    > >> an
    > >> object.Source Error: Line 4:
    > >> Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e As
    > >> System.EventArgs) Handles Me.Error
    > >> Line 6: Throw Server.GetLastError()
    > >> Line 7: End Sub
    > >> Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb
    > >> Line:
    > >> 6 Any ideas?Also, I'm under the impression that if an actual error
    > >> occurs,
    > >> it will not send me to the error page as specified b/c I'm on my
    > >> development
    > >> machine. is that correct?Thanks!!-- David
    > >> Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com
    > >>
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?R2FydGhT?=, Jul 21, 2006
    #4
  5. David Lozzi

    David Lozzi Guest

    I take great offense to the thickness of my own skull! Thank you, I'll try
    that soon.
    --
    David Lozzi
    dlozzi@(remove)delphi-ts.com
    www.delphi-ts.com


    "GarthS" <> wrote in message
    news:...
    > David,
    > I ran a quick test and had no problem throwing the Server.GetLastError
    > within the Page_Error, redirection to the error page occured as expected.
    > I'll ask a question, and I hope I don't offend ;), have you set the mode
    > of
    > your customErrors section to 'On'?
    > eg:
    > <customErrors defaultRedirect="~/Error.aspx" mode="On">
    > </customErrors>
    >
    > If the mode is Off or RemoteOnly on your development machine you'll get
    > the
    > standard server error.
    >
    > As an aside, I don't normally mind the exceptions being wrapped in an
    > HttpUnhandledException. You can get the original exception from the
    > InnerException property of the unhandled exception in the
    > application_error
    > event. I guess a down side (or up side depending on how you look at it)
    > to
    > this is that HttpUnhandledExceptions are logged in the Application log on
    > the
    > server.
    >
    > Garth.
    >
    >
    > "David Lozzi" wrote:
    >
    >> The book states to "rethrow the last exception that occured...we do this
    >> step to avoid having the exception information wrapped with an
    >> HttpUnhandledException exception. ASP.NET automatically creates a new
    >> HttpUnhandledException at the page level unless you rethrow the last
    >> exception." sooo.....
    >>
    >> --
    >> David Lozzi
    >> dlozzi@(remove)delphi-ts.com
    >> www.delphi-ts.com
    >>
    >>
    >> "GarthS" <> wrote in message
    >> news:...
    >> > David,
    >> > You shouldn't have to rethrow the sever last error in your page_error
    >> > event. As long as you don't call Server.ClearError() the
    >> > Application_Error
    >> > event should still fire and redirection to the error page should occur
    >> > as
    >> > defined in your web.config.
    >> >
    >> > Incidentally, I normally use the Page_Error event to perform page state
    >> > clean up and the Application_Error event in the global.asax for custom
    >> > error
    >> > handling (such as calling an EntLib exception policy - which could you
    >> > caould
    >> > configure to do your emailing and logging functions).
    >> >
    >> > Depending on the deployment I sometimes use a custom HTTPModule for
    >> > hooking
    >> > in to application events. If I want to change how I'm handling an
    >> > application error then I cna change and redeploy th HTTPModule dll
    >> > rather
    >> > than playing with the global.asax.
    >> >
    >> > Hope this helps,
    >> > Garth
    >> >
    >> > "David Lozzi" wrote:
    >> >
    >> >> Howdy,
    >> >>
    >> >> I found a nice little book called ASP.NET 2.0 Cookbook by Michael A
    >> >> Kittel
    >> >> and Geoffrey LeBlond. Anyway, they have some instructions on how to
    >> >> setup
    >> >> application level error handling. Most of my functions have try..catch
    >> >> to
    >> >> email me about an error, then I want the application level to fire off
    >> >> to
    >> >> send the user to a custom page AND log it in the app log. When an
    >> >> error
    >> >> occurs on my page, i get a server error
    >> >>
    >> >> Server Error in '/newcart' Application.
    >> >> --------------------------------------------------------------------------------
    >> >>
    >> >> Object reference not set to an instance of an object.
    >> >> Description: An unhandled exception occurred during the execution of
    >> >> the
    >> >> current web request. Please review the stack trace for more
    >> >> information
    >> >> about the error and where it originated in the code. Exception
    >> >> Details:
    >> >> System.NullReferenceException: Object reference not set to an instance
    >> >> of
    >> >> an
    >> >> object.Source Error: Line 4:
    >> >> Line 5: Protected Sub Page_Error(ByVal sender As Object, ByVal e
    >> >> As
    >> >> System.EventArgs) Handles Me.Error
    >> >> Line 6: Throw Server.GetLastError()
    >> >> Line 7: End Sub
    >> >> Line 8: Source File: c:\inetpub\wwwroot\newcart\addtobag.aspx.vb
    >> >> Line:
    >> >> 6 Any ideas?Also, I'm under the impression that if an actual error
    >> >> occurs,
    >> >> it will not send me to the error page as specified b/c I'm on my
    >> >> development
    >> >> machine. is that correct?Thanks!!-- David
    >> >> Lozzidlozzi@(remove)delphi-ts.comwww.delphi-ts.com
    >> >>
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
    David Lozzi, Jul 21, 2006
    #5
    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. MS News \(MS ILM\)

    File upload limit handleing

    MS News \(MS ILM\), Aug 18, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    588
    MS News \(MS ILM\)
    Aug 20, 2004
  2. Replies:
    2
    Views:
    428
  3. Ola Natvig

    new style exception handleing

    Ola Natvig, Feb 2, 2005, in forum: Python
    Replies:
    4
    Views:
    292
    Nick Coghlan
    Feb 3, 2005
  4. pabbu
    Replies:
    8
    Views:
    707
    Marc Boyer
    Nov 7, 2005
  5. Jéjé
    Replies:
    0
    Views:
    220
    Jéjé
    Sep 27, 2005
Loading...

Share This Page