473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Trapping 'compile' errors when aspx page is rendered.

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.
Nov 19 '05 #1
4 2075
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/de...orssection.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.


Nov 19 '05 #2
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/de...orssection.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.


Nov 19 '05 #3
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/...B&P=R3885&I=-3

http://discuss.develop.com/archives/...B&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/de...ary/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.


Nov 19 '05 #4
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/...B&P=R3885&I=-3

http://discuss.develop.com/archives/...B&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/de...ary/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.


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JP | last post by:
I need to be able to trap errors at the application level. I added this code to the Global.asax file. The code I wrote is supposed to get the last error that was generated and write to the event...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
4
by: Lowell | last post by:
Any tips for trouble shooting errors when the ASPX page won't even compile? What happens is that VS will "build" the code-behind object and the component that it instantiates, but when I navigate to...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a...
6
by: SMG | last post by:
Hi , Sory for incomplete message in last post here is the actual problem.. I am using following code in web.confiig for trapping all the error through out my site.. <customErrors mode="On"...
2
by: Fred Nelson | last post by:
I'm devloping a VB.NET web application and I'm having a problem with trapping errors and logging the cause of them. When an unexpected error occurs I want to write it to a file - or e-mail it to...
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
1
by: =?Utf-8?B?SG93YXJkIFBpbnNsZXk=?= | last post by:
I'm trying to convert a Web Site to the Web Application project model and I'm running into compile errors that do not seem to be covered by the guidance I found at "Converting a Web Site Project to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.