473,729 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error handling not working

This has been driving me crazy.

I have been trying to get the error handling working on my system and can
get parts of it working and others won't work at all.

I found that you can't access session variables from Application_Err or
event, but I need to so I don't need to set up traces to see what they are
during an error. I am emailing the error condition to myself when it
happens.

So I moved the code to one of my error pages and it works fine if called
directly. So I added this code to my Application_Err or routine:

Sub Application_Err or(Sender As Object, E as EventArgs)
response.Redire ct("/PageError.aspx" )
End Sub

And it goes fine to my error page which emails my session variables to me,
but when I try to do:

Dim exception As Exception = Server.GetLastE rror()

I get nothing. I assume the Application_Err or routine cleared it.

I then tried to comment out the Application_Err or code so it would go to the
CustomErrors in my webconfig file:

<customErrors defaultRedirect ="PageUnavailab le.aspx" mode="Off" />

but the page is never called - it goes to the MS Error page. If Change mode
to "On",

<customErrors defaultRedirect ="PageUnavailab le.aspx" mode="On" />

I get the following page:

*************** *************** *************** *************** *********
Runtime Error
Description: An application error occurred on the server. The current custom
error settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could, however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable
on remote machines, please create a <customErrors > tag within a "web.config "
configuration file located in the root directory of the current web
application. This <customErrors > tag should then have its "mode" attribute
set to "Off".
<!-- Web.Config Configuration File -->

<configuratio n>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirec t" attribute of the application's
<customErrors > configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->

<configuratio n>
<system.web>
<customErrors mode="RemoteOnl y" defaultRedirect ="mycustompage. htm"/>
</system.web>
</configuration>
*************** *************** *************** *************** *************** *********

I also tried setting up a Page_Error in my program and it never gets called.

I don't understand why this is a problem.

Tom
Feb 22 '06 #1
2 2141
Tom,
you want to do this:

Exception ex= Server.GetLastE rror().GetBaseE xception()

at this point, if you want, you could possibly even store the exception in
Session and then do your redirect.
GetBaseExceptio n retrieves the "real" innerException object.

Here's a pretty good article with some more ideas:
http://www.developer.com/net/asp/article.php/961301

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"tshad" wrote:
This has been driving me crazy.

I have been trying to get the error handling working on my system and can
get parts of it working and others won't work at all.

I found that you can't access session variables from Application_Err or
event, but I need to so I don't need to set up traces to see what they are
during an error. I am emailing the error condition to myself when it
happens.

So I moved the code to one of my error pages and it works fine if called
directly. So I added this code to my Application_Err or routine:

Sub Application_Err or(Sender As Object, E as EventArgs)
response.Redire ct("/PageError.aspx" )
End Sub

And it goes fine to my error page which emails my session variables to me,
but when I try to do:

Dim exception As Exception = Server.GetLastE rror()

I get nothing. I assume the Application_Err or routine cleared it.

I then tried to comment out the Application_Err or code so it would go to the
CustomErrors in my webconfig file:

<customErrors defaultRedirect ="PageUnavailab le.aspx" mode="Off" />

but the page is never called - it goes to the MS Error page. If Change mode
to "On",

<customErrors defaultRedirect ="PageUnavailab le.aspx" mode="On" />

I get the following page:

*************** *************** *************** *************** *********
Runtime Error
Description: An application error occurred on the server. The current custom
error settings for this application prevent the details of the application
error from being viewed remotely (for security reasons). It could, however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable
on remote machines, please create a <customErrors > tag within a "web.config "
configuration file located in the root directory of the current web
application. This <customErrors > tag should then have its "mode" attribute
set to "Off".
<!-- Web.Config Configuration File -->

<configuratio n>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirec t" attribute of the application's
<customErrors > configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->

<configuratio n>
<system.web>
<customErrors mode="RemoteOnl y" defaultRedirect ="mycustompage. htm"/>
</system.web>
</configuration>
*************** *************** *************** *************** *************** *********

I also tried setting up a Page_Error in my program and it never gets called.

I don't understand why this is a problem.

Tom

Feb 22 '06 #2
That will get me the last error, but I am trying to get all the errors and
am looping through the innerException object. The GetBaseExceptio n also
gets me the last one, which would be fine. But I found that the error
response I get back is unreadable.

If I don't do the Application_Err or, I get this error:

*************** *************** *************** *************** *******
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'SearchType' is not declared.

Source Error:

Line 89: Else
Line 90: 'We aren't dealing with an array, so just display the
variable
Line 91: if
SearchType.Inde xOf(Session.Con tents(strName). GetType.ToStrin g()) >= 0 then
Line 92: trace.warn(strN ame & " - " & Session.Content s(strName) & "
" & Session.Content s(strName).GetT ype.ToString)
Line 93: else

Source File:
C:\Inetpub\wwwr oot\staffingwor kshop\ADMINISTR ATION\showExcep tions.aspx
Line: 91

*************** *************** *************** *************** *******

If I do the following:

*************** *************** *************** *************** *******
Sub Application_Err or(Sender As Object, E as EventArgs)
Dim exception As Exception = Server.GetLastE rror().GetBaseE xception()
Dim ErrorString as String

While Not exception Is Nothing
ErrorString &= "Source: " & exception.Sourc e & vbCrLf & _
"Message: " & exception.Messa ge & vbCrLf & _
"Stack Trace: " & vbCrLf & exception.Stack Trace & vbCrLf &
vbCrLf
exception = exception.Inner Exception
End While

Dim MyMessage as New MailMessage
MyMessage.To = tf*@ftsos.com
MyMessage.From = "tf*@ftsos. com"
MyMessage.Subje ct = "Unhandled ASP.Net Error"
MyMessage.Body = vbCrLf & vbCrLf & "An Error was Generated on " & now &
vbCrLf & vbCrLf & _
"To see a list of Errors:
HTTP:\\www.staf fingworkshop.co m\administratio n\showException s.aspx" & vbCrLf
& vbCrLf & _
"Page: " & HTTPContext.Cur rent.Request.Ur l.ToString() & vbCrLf &
vbCrLf & ErrorString

SmtpMail.SmtpSe rver = Application("Ma ilServer")
SmtpMail.Send(M yMessage)

Context.ClearEr ror()
response.Redire ct("/PageError.aspx" )
End Sub
*************** *************** *************** *************** *******

I get the following results:

*************** *************** *************** *************** ********
An Error was Generated on 2/21/2006 5:39:25 PM

To see a list of Errors:
HTTP:\\http://www.staffingworkshop.com\admi...xceptions.aspx

Page: http://www.staffingworkshop.com/ADMI...xceptions.aspx

Source: System.Web
Message: External component has thrown an exception.
Stack Trace:
at
System.Web.Comp ilation.BaseCom piler.ThrowIfCo mpilerErrors(Co mpilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData, String
sourceFile, String sourceString)
at System.Web.Comp ilation.BaseCom piler.GetCompil edType()
at System.Web.UI.P ageParser.Compi leIntoType()
at System.Web.UI.T emplateParser.G etParserCacheIt emThroughCompil ation()
*************** *************** *************** *************** ********

If I take out the GetBaseExceptio n():

Dim exception As Exception = Server.GetLastE rror().GetBaseE xception()

I get

*************** *************** *************** *************** ***********
An Error was Generated on 2/21/2006 5:41:49 PM

To see a list of Errors:
HTTP:\\http://www.staffingworkshop.com\admi...xceptions.aspx

Page: http://www.staffingworkshop.com/ADMI...xceptions.aspx

Source: System.Web
Message: External component has thrown an exception.
Stack Trace:
at System.Web.UI.T emplateParser.G etParserCacheIt emInternal(Bool ean
fCreateIfNotFou nd)
at System.Web.UI.T emplateParser.G etParserCacheIt emWithNewConfig Path()
at System.Web.UI.T emplateParser.G etParserCacheIt em()
at
System.Web.UI.T emplateControlP arser.CompileAn dGetParserCache Item(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.T emplateControlP arser.GetCompil edInstance(Stri ng
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.P ageParser.GetCo mpiledPageInsta nceInternal(Str ing
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.P ageHandlerFacto ry.GetHandler(H ttpContext context,
String requestType, String url, String path)
at System.Web.Http Application.Map HttpHandler(Htt pContext context, String
requestType, String path, String pathTranslated, Boolean useAppConfig)
at
System.Web.MapH andlerExecution Step.System.Web .HttpApplicatio n+IExecutionSte p.Execute()
at System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean&
completedSynchr onously)

Source: System.Web
Message: External component has thrown an exception.
Stack Trace:
at
System.Web.Comp ilation.BaseCom piler.ThrowIfCo mpilerErrors(Co mpilerResults
results, CodeDomProvider codeProvider, CodeCompileUnit sourceData, String
sourceFile, String sourceString)
at System.Web.Comp ilation.BaseCom piler.GetCompil edType()
at System.Web.UI.P ageParser.Compi leIntoType()
at System.Web.UI.T emplateParser.G etParserCacheIt emThroughCompil ation()

*************** *************** *************** *************** ***********

Either way there is nothing like: BC30451: Name 'SearchType' is not
declared.

Where do you get that?

These message are pretty useless without it.

Thanks,

Tom

"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:8C******** *************** ***********@mic rosoft.com...
Tom,
you want to do this:

Exception ex= Server.GetLastE rror().GetBaseE xception()

at this point, if you want, you could possibly even store the exception in
Session and then do your redirect.
GetBaseExceptio n retrieves the "real" innerException object.

Here's a pretty good article with some more ideas:
http://www.developer.com/net/asp/article.php/961301

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"tshad" wrote:
This has been driving me crazy.

I have been trying to get the error handling working on my system and can
get parts of it working and others won't work at all.

I found that you can't access session variables from Application_Err or
event, but I need to so I don't need to set up traces to see what they
are
during an error. I am emailing the error condition to myself when it
happens.

So I moved the code to one of my error pages and it works fine if called
directly. So I added this code to my Application_Err or routine:

Sub Application_Err or(Sender As Object, E as EventArgs)
response.Redire ct("/PageError.aspx" )
End Sub

And it goes fine to my error page which emails my session variables to
me,
but when I try to do:

Dim exception As Exception = Server.GetLastE rror()

I get nothing. I assume the Application_Err or routine cleared it.

I then tried to comment out the Application_Err or code so it would go to
the
CustomErrors in my webconfig file:

<customErrors defaultRedirect ="PageUnavailab le.aspx" mode="Off" />

but the page is never called - it goes to the MS Error page. If Change
mode
to "On",

<customErrors defaultRedirect ="PageUnavailab le.aspx" mode="On" />

I get the following page:

*************** *************** *************** *************** *********
Runtime Error
Description: An application error occurred on the server. The current
custom
error settings for this application prevent the details of the
application
error from being viewed remotely (for security reasons). It could,
however,
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be
viewable
on remote machines, please create a <customErrors > tag within a
"web.config "
configuration file located in the root directory of the current web
application. This <customErrors > tag should then have its "mode"
attribute
set to "Off".
<!-- Web.Config Configuration File -->

<configuratio n>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom
error page by modifying the "defaultRedirec t" attribute of the
application's
<customErrors > configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->

<configuratio n>
<system.web>
<customErrors mode="RemoteOnl y"
defaultRedirect ="mycustompage. htm"/>
</system.web>
</configuration>
*************** *************** *************** *************** *************** *********

I also tried setting up a Page_Error in my program and it never gets
called.

I don't understand why this is a problem.

Tom

Feb 22 '06 #3

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

Similar topics

1
5037
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
6
8461
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order by VisitDt" I'm getting this error message: Errno is 2465. Err.description is "Can't find field '|' referred to in your expression"
1
483
by: michaeltorus | last post by:
Hi I'm currently designing a new web application in .Net. I've pretty covered everything, apart from error handling. There seems to be a few different way to do this, but something I've read often is that loading all your code with lots of try / catch blocks is not the best way. My application is made up of a number of different sub applications. A CRM Package, with financial services, compliance and commisions etc etc. Each part has...
3
2056
by: Mr Newbie | last post by:
I'm testing error handling configurations and having some trouble. I created a WebForm called. ErrDefault.aspx and I am trying to use the Page error attribute to force the redirection to a custom page, but I only get and unhandled exception page and it does not direct me to my specific page. I'm probably doing something really stupid, but I cant see what . Any Ideas ? - Thanx Mr N --------- DETAILS BELOW -----------
9
2228
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that I have been doing it right. I think I overdo it. Please have a look: -- using System; using System.IO;
10
2290
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on that ID, otherwise it returns false. **I am not looking for comments on the usefulness of this function - it is
4
1850
by: DavideR | last post by:
I have converted a large vb6 program with an add-in that for every routine gimme the error handling: the add-in adds one line on the head of the routine "if myerrhandle then ON ERROR GOTO HERRHANDLER" and the herrhandler label at the botton where i write in a logfile the name of the routine, the errors and other information Well setting myerrhandle to true seems that the error handling keeps on working in ..net is it right? what's the...
0
3623
by: dhyder | last post by:
I'm working on an admin page for a SQL Server 05 db. The page is in ASP.NET 2.0/C#. The db has multiple tables with foreign keys/constraints. I have multiple SqlDataSources and GridViews, which are doing the select/update/delete methods. I manually did the Insert method for each Gridview and I am able perform error handling on it. Textboxes for data to add <asp:Button ID="btnInsertNewService runat="server" Text="Submit"...
9
2074
by: Trapulo | last post by:
Hello, with ASP.NET 2.0 Ajax every unexpected error is managed client-side with a popup that reports the error to the user. In ASP.NET 3.5 this behavor has been changed: how can I have a similar behavor? I'd like that every exception raised from ASP.NET runtime during an asyncpostback is managed in client side with a popup that reports the error message. thanks
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.