R
Raterus
Hi,
I've got a quick question for anyone that knows something about exception handling. I'm handling most of my errors in Application_Error in global.asax, and I'd like to pass some state information about the application along with the entire error: Say I have the following try/catch block
try
conn.open
cmd.ExecuteNonQuery
Catch (ex as Exception)
throw
Finally
conn.close
End Try
Say I have some information I know about the query that executed at runtime, like the sql query used, values of parameters added, current state of the application, etc, and I wanted to tack these on to the error message, so my application_error Sub can pick up on them. I haven't figured out a good way to do this? I tried adding to the "HelpLink" property, but when I call Server.GetLastError in Application_Error, it isn't there. I also don't want to throw away the Stack Information, so I don't want to use throw(ex). Does anyone know if this is possible? It would look something like this I think.
try
conn.open
cmd.ExecuteNonQuery
Catch (ex as Exception)
ex.HelpLink = "Sql Statement Used: " & sql & "Parameter @a: " & cmd.parameters("@a").value
throw
Finally
conn.close
End Try
I have figured out I can at least add some information to the Context (through Context.Items), but there is no guarantee the object I'm currently executing in has access to this object. And I don't think it would be a good practice to start making calls to HttpContext.Current from within my objects that really don't know anything about asp.net.
Thanks for any help,
--Michael
I've got a quick question for anyone that knows something about exception handling. I'm handling most of my errors in Application_Error in global.asax, and I'd like to pass some state information about the application along with the entire error: Say I have the following try/catch block
try
conn.open
cmd.ExecuteNonQuery
Catch (ex as Exception)
throw
Finally
conn.close
End Try
Say I have some information I know about the query that executed at runtime, like the sql query used, values of parameters added, current state of the application, etc, and I wanted to tack these on to the error message, so my application_error Sub can pick up on them. I haven't figured out a good way to do this? I tried adding to the "HelpLink" property, but when I call Server.GetLastError in Application_Error, it isn't there. I also don't want to throw away the Stack Information, so I don't want to use throw(ex). Does anyone know if this is possible? It would look something like this I think.
try
conn.open
cmd.ExecuteNonQuery
Catch (ex as Exception)
ex.HelpLink = "Sql Statement Used: " & sql & "Parameter @a: " & cmd.parameters("@a").value
throw
Finally
conn.close
End Try
I have figured out I can at least add some information to the Context (through Context.Items), but there is no guarantee the object I'm currently executing in has access to this object. And I don't think it would be a good practice to start making calls to HttpContext.Current from within my objects that really don't know anything about asp.net.
Thanks for any help,
--Michael