Trapping 'compile' errors when aspx page is rendered.

Discussion in 'ASP .Net' started by =?Utf-8?B?QmlsbA==?=, Mar 29, 2005.

  1. Despite our best efforts occasionally in an aspx file, something like <%=x%>
    where x is not defined sqeaks by and I get the ugly asp error message. I want
    to be able to identify this particular error and issue a pretty message. I
    use the global.asax on application error to handle generalized error
    handling. I want to be able to capture and identify the above error.
    =?Utf-8?B?QmlsbA==?=, Mar 29, 2005
    #1
    1. Advertising

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

    Brock Allen Guest

    Look into the <customErrors> section in web.config -- it allows you to configure
    a nice user friendly page that the user will get redirected to when there
    are unhandled exceptions in your application.

    http://msdn.microsoft.com/library/d...us/cpgenref/html/gngrfcustomerrorssection.asp

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



    > Despite our best efforts occasionally in an aspx file, something like
    > <%=x%> where x is not defined sqeaks by and I get the ugly asp error
    > message. I want to be able to identify this particular error and issue
    > a pretty message. I use the global.asax on application error to handle
    > generalized error handling. I want to be able to capture and identify
    > the above error.
    >
    Brock Allen, Mar 29, 2005
    #2
    1. Advertising

  3. I beleive when I use when I use the global.asax on application error that it
    does get control when this situation occurs. If possible I would like to
    identify it there(in the global.asax). All of the error handleing is located
    in one program that is server.transfered to.



    "Brock Allen" wrote:

    > Look into the <customErrors> section in web.config -- it allows you to configure
    > a nice user friendly page that the user will get redirected to when there
    > are unhandled exceptions in your application.
    >
    > http://msdn.microsoft.com/library/d...us/cpgenref/html/gngrfcustomerrorssection.asp
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > Despite our best efforts occasionally in an aspx file, something like
    > > <%=x%> where x is not defined sqeaks by and I get the ugly asp error
    > > message. I want to be able to identify this particular error and issue
    > > a pretty message. I use the global.asax on application error to handle
    > > generalized error handling. I want to be able to capture and identify
    > > the above error.
    > >

    >
    >
    >
    >
    =?Utf-8?B?QmlsbA==?=, Mar 29, 2005
    #3
  4. =?Utf-8?B?QmlsbA==?=

    Brock Allen Guest

    I see what you're saying. You use Application_Error to do all of your error
    trapping and then redirect from there. Ok, you can do that, but it's defeating
    the purpose of the <customErrors>.

    Anyway, to determine if the error comes from your code or elsewhere you should
    check to see if the Context.Error is an HttpUnhandledException. If so, then
    the unhandled exception is something from your code (like a cast error, DBConnection
    error, that sort of thing) that occurs at runtime. The Context.Error.InnerException
    tells the real story as to why the error occured.

    If it's a typo in the ASPX page, then the error is a HttpException with an
    InnerException of HttpCompileException.

    So you might code it like this:

    protected void Application_Error(Object sender, EventArgs e)
    {
    Exception ex = Context.Error;
    if (ex is HttpUnhandledException)
    {
    // my problem
    Server.Transfer("error.aspx");
    }
    else if (ex is HttpException)
    {
    if (ex.InnerException is HttpCompileException)
    {
    // typo in ASPX
    Server.Transfer("SendEmailToDevTeam.aspx");
    }
    }

    }

    Though personally I'd find this very tedious to maintain. We discussed this
    a couple fo weeks ago on DevelopMentor's listservs:

    http://discuss.develop.com/archives/wa.exe?A2=ind0502B&L=DOTNET-WEB&P=R3885&I=-3

    http://discuss.develop.com/archives/wa.exe?A2=ind0502B&L=DOTNET-WEB&P=R3787&I=-3

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



    > I beleive when I use when I use the global.asax on application error
    > that it does get control when this situation occurs. If possible I
    > would like to identify it there(in the global.asax). All of the error
    > handleing is located in one program that is server.transfered to.
    >
    > "Brock Allen" wrote:
    >
    >> Look into the <customErrors> section in web.config -- it allows you
    >> to configure a nice user friendly page that the user will get
    >> redirected to when there are unhandled exceptions in your
    >> application.
    >>
    >> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpge
    >> nref/html/gngrfcustomerrorssection.asp
    >>
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>> Despite our best efforts occasionally in an aspx file, something
    >>> like <%=x%> where x is not defined sqeaks by and I get the ugly asp
    >>> error message. I want to be able to identify this particular error
    >>> and issue a pretty message. I use the global.asax on application
    >>> error to handle generalized error handling. I want to be able to
    >>> capture and identify the above error.
    >>>
    Brock Allen, Mar 29, 2005
    #4
  5. You are a wonder !!!! Thanks very much for for answering my question exactly
    as I was hoping for. Thanks Much !

    "Brock Allen" wrote:

    > I see what you're saying. You use Application_Error to do all of your error
    > trapping and then redirect from there. Ok, you can do that, but it's defeating
    > the purpose of the <customErrors>.
    >
    > Anyway, to determine if the error comes from your code or elsewhere you should
    > check to see if the Context.Error is an HttpUnhandledException. If so, then
    > the unhandled exception is something from your code (like a cast error, DBConnection
    > error, that sort of thing) that occurs at runtime. The Context.Error.InnerException
    > tells the real story as to why the error occured.
    >
    > If it's a typo in the ASPX page, then the error is a HttpException with an
    > InnerException of HttpCompileException.
    >
    > So you might code it like this:
    >
    > protected void Application_Error(Object sender, EventArgs e)
    > {
    > Exception ex = Context.Error;
    > if (ex is HttpUnhandledException)
    > {
    > // my problem
    > Server.Transfer("error.aspx");
    > }
    > else if (ex is HttpException)
    > {
    > if (ex.InnerException is HttpCompileException)
    > {
    > // typo in ASPX
    > Server.Transfer("SendEmailToDevTeam.aspx");
    > }
    > }
    >
    > }
    >
    > Though personally I'd find this very tedious to maintain. We discussed this
    > a couple fo weeks ago on DevelopMentor's listservs:
    >
    > http://discuss.develop.com/archives/wa.exe?A2=ind0502B&L=DOTNET-WEB&P=R3885&I=-3
    >
    > http://discuss.develop.com/archives/wa.exe?A2=ind0502B&L=DOTNET-WEB&P=R3787&I=-3
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > I beleive when I use when I use the global.asax on application error
    > > that it does get control when this situation occurs. If possible I
    > > would like to identify it there(in the global.asax). All of the error
    > > handleing is located in one program that is server.transfered to.
    > >
    > > "Brock Allen" wrote:
    > >
    > >> Look into the <customErrors> section in web.config -- it allows you
    > >> to configure a nice user friendly page that the user will get
    > >> redirected to when there are unhandled exceptions in your
    > >> application.
    > >>
    > >> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpge
    > >> nref/html/gngrfcustomerrorssection.asp
    > >>
    > >> -Brock
    > >> DevelopMentor
    > >> http://staff.develop.com/ballen
    > >>> Despite our best efforts occasionally in an aspx file, something
    > >>> like <%=x%> where x is not defined sqeaks by and I get the ugly asp
    > >>> error message. I want to be able to identify this particular error
    > >>> and issue a pretty message. I use the global.asax on application
    > >>> error to handle generalized error handling. I want to be able to
    > >>> capture and identify the above error.
    > >>>

    >
    >
    >
    >
    =?Utf-8?B?QmlsbA==?=, Mar 29, 2005
    #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. Robin Dindayal

    Print rendered .aspx page to server's printer

    Robin Dindayal, Jul 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    593
    Robin Dindayal
    Jul 25, 2003
  2. Jon Maz
    Replies:
    10
    Views:
    646
    Jon Maz
    Feb 11, 2004
  3. Hose B
    Replies:
    1
    Views:
    3,882
    Scott Allen
    Jul 2, 2004
  4. Eitan
    Replies:
    3
    Views:
    126
    Bob Barrows [MVP]
    Jan 12, 2005
  5. Gerard A.W. Vreeswijk

    trapping compile time errors

    Gerard A.W. Vreeswijk, Jul 7, 2003, in forum: Ruby
    Replies:
    5
    Views:
    125
    Robert Klemme
    Jul 7, 2003
Loading...

Share This Page