PDA

Click to See Complete Forum and Search --> : Error Handling - clearing an exception


PedroDePacos
Mar 4th, 2004, 05:43 AM
Hello,

I have nested try...catch statements that I use for error handling. I was wondering if there was any way to clear an error so that if an exception is encountered in a nested try...catch statement.

I've tried Err.Clear(), Server.ClearError(), Context.ClearError() and none of these work.


Try
'do something

Try
'do something

Catch DefaultExc As Exception
Context.ClearError()
Server.ClearError()
Err.Clear()

End Try

'the code here does not get processed when an error is caught in the try...catch statement above

Catch DefaultExc As Exception
'errors processed in the above catch statement always get processed here as
'well and I just want to clear the error in the first nested catch statement

End Try

axion_sa
Mar 4th, 2004, 12:16 PM
The catch itself clears the exception, unless you throw it again.

The code should run - are you sure an exception isn't being raised before the nested try...catch?

PedroDePacos
Mar 4th, 2004, 02:27 PM
That's what I thought and I'm positive the exception is not being raised before the nested try...catch. The specific exception that I'm raising is ThreadAbortException from Server.Transfer(Path) or Response.Redirect(Path). Does this have anything to do with it?

axion_sa
Mar 5th, 2004, 12:42 PM
That would have something to do with it - from MSDN (both HttpResponse.Redirect & Server.Transfer):

Redirect calls End which raises a ThreadAbortException exception upon completion.