Global.asax not working

T

tshad

I have my error handling set up in Global.asax:

Sub Application_Error(Sender As Object, E as EventArgs)

In this procedure I call a function in a dll that will write out to a
history file.

This works for some errors, but not others. If it doesn't work, it stops
there and the normal MS error page goes to the User.

For example:

I have the following error:

***************************************************
Compiler Error Message: BC30684: 'DataSet' is a type and cannot be used as
an expression.

Source Error:

Line 65: Dim parameters() As SqlParameter
Line 66:
Line 67: DataSet = myDbObject.RunProcedure("GetScheduleNames", parameters,
"HistoryLog")
Line 68: HistoryLogGrid.DataSource = ds
Line 69: HistoryLogGrid.DataBind()
********************************************************

I know why I got the error, but I would have expected my Global error
handler to handle it.

But it doesn't.

The reason it doesn't handle it is because of this code:

if not HttpContext.Current.Session.SessionID is nothing then
parameters(0).value = HttpContext.Current.Session.SessionID
else
parameters(0).value = ""
end if

If I even reference "HttpContext.Current.Session.SessionID", it dies.

I assume that is because this is an error where ASP is checking the page for
errors before actually handling it and there is no SessionID. If it was a
logic error, this works fine and I can access the SessionID in my Global
error routine.

Why can't I here????

Or at least check if it exists.

I need to find out how to handle this or my Global Error routine is not
going to work.

Thanks,

Tom
 
T

tdavisjr

I think you have got it wrong. You are treating all errors the same.
There are compile time errors and errors triggered by exceptions. Your
error with the dataset is a compile time error and will not be handled
by Application_Error. However, if somehow your sql connection blows up
then an exception will be thrown and your Application_Error should
handle it only if the error happens outside of the event handler ( not
too sure about this). But, the point is that not all errors of the
same.

For example, if you had an computational error in your code I'm sure
you won't expect Application_Error to catch that. Same goes here.
 
T

tshad

If I take this line out
tdavisjr said:
I think you have got it wrong. You are treating all errors the same.
There are compile time errors and errors triggered by exceptions. Your
error with the dataset is a compile time error and will not be handled
by Application_Error. However, if somehow your sql connection blows up
then an exception will be thrown and your Application_Error should
handle it only if the error happens outside of the event handler ( not
too sure about this). But, the point is that not all errors of the
same.

I agree.

But in this case, the Applicant_Error routine did catch the error. It
actually went through the whole process (where it sends me an email), but as
soon as I accessed the "HttpContext.Current.Session.SessionID", it stopped.

I know this because I put some code into the HistoryLog routine wrote to a
text file.

But if I replace the 5 lines of code with:

parameters(0).value = ""

It works fine.

It was the accessing of the SessionID that caused it to stop working.

I thought that if I checked to see if it was "nothing", that would solve the
problem, but it didn't.

Thanks,

Tom
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top