Trapping 'compile' errors when aspx page is rendered.

G

Guest

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.
 
G

Guest

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.
 
B

Brock Allen

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
 
G

Guest

You are a wonder !!!! Thanks very much for for answering my question exactly
as I was hoping for. Thanks Much !
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top