G
Girish
so I was looking at an example on codeproject.com that talked about how to
globalize your error handling. I was extremely confused by some code. Id
appreciate if someone could help me out by understanding this.
URL if anyone is interested:
http://www.codeproject.com/aspnet/JcGlobalErrorHandling.asp#xx726891xx
1) Ok, so in short, the way to do this error handling is to set a STATIC
variable in some class whenever an error occurs. Global.aspx file:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Utilities.LastError = Server.GetLastError()
End Sub
2) Decl of Utility Class:
Public Class Utilities
Public Shared LastError As System.Exception
End Class
3) Obviously set the customErrors handler in web.config:
<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
4) In the ErrorPage.aspx page, you have the following code to get the error
back from the STATIC variable:
With Utilities.LastError.InnerException
Dim r0 As DataRow = t.NewRow
r0(0) = "Message"
r0(1) = .Message
t.Rows.Add(r0)
Dim r1 As DataRow = t.NewRow
r1(0) = "StackTrace"
r1(1) = .StackTrace.Replace(vbCr, "<br>")
t.Rows.Add(r1)
Dim r2 As DataRow = t.NewRow
r2(0) = "Source"
r2(1) = .Source
t.Rows.Add(r2)
End With
Sorry for the mixing up of concepts/code between c# and vb.net, but heres my
problem: I understand what static variables are. And I understand that once
set, they are set for the whole application process. (Im stating process -
but maybe its threads. I dont really know. Does IIS choose from pool or
create one thread per one hit to the application webiste?)
Anyways, so if someone(User1) were to come on the website and an error
occurred, the static variable would be set and the person would be
redirected. Now what in the name of the world would happen IFF before the
redirect to the errorpage, User1's processing gets preempted and ANOTHER
user (User2) were to hit the website and get a different exception. The SAME
static variable would be set to a new error. Right?
Now processing continues and User1's error page renders with User2's error
code???!
I dont get it.
Girish
globalize your error handling. I was extremely confused by some code. Id
appreciate if someone could help me out by understanding this.
URL if anyone is interested:
http://www.codeproject.com/aspnet/JcGlobalErrorHandling.asp#xx726891xx
1) Ok, so in short, the way to do this error handling is to set a STATIC
variable in some class whenever an error occurs. Global.aspx file:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Utilities.LastError = Server.GetLastError()
End Sub
2) Decl of Utility Class:
Public Class Utilities
Public Shared LastError As System.Exception
End Class
3) Obviously set the customErrors handler in web.config:
<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
4) In the ErrorPage.aspx page, you have the following code to get the error
back from the STATIC variable:
With Utilities.LastError.InnerException
Dim r0 As DataRow = t.NewRow
r0(0) = "Message"
r0(1) = .Message
t.Rows.Add(r0)
Dim r1 As DataRow = t.NewRow
r1(0) = "StackTrace"
r1(1) = .StackTrace.Replace(vbCr, "<br>")
t.Rows.Add(r1)
Dim r2 As DataRow = t.NewRow
r2(0) = "Source"
r2(1) = .Source
t.Rows.Add(r2)
End With
Sorry for the mixing up of concepts/code between c# and vb.net, but heres my
problem: I understand what static variables are. And I understand that once
set, they are set for the whole application process. (Im stating process -
but maybe its threads. I dont really know. Does IIS choose from pool or
create one thread per one hit to the application webiste?)
Anyways, so if someone(User1) were to come on the website and an error
occurred, the static variable would be set and the person would be
redirected. Now what in the name of the world would happen IFF before the
redirect to the errorpage, User1's processing gets preempted and ANOTHER
user (User2) were to hit the website and get a different exception. The SAME
static variable would be set to a new error. Right?
Now processing continues and User1's error page renders with User2's error
code???!
I dont get it.
Girish