Thursday, 29 May 2008

.NET: Ignoring Thread Abort Exception in Enterprise Library Exception Handling

Noticed that the trace.log in TRAKIT was filling up rather quickly.
Whenever it hits a response.redirect, .NET was generating a thread abort exception.

To ignore, do this:

try{
//your try block
}catch(System.Threading.ThreadAbortException ex)
//exception ignored to prevent logging in trace.log
}catch(Exception ex){
//catch error using Enterpise Library logging
bool rethrow = ExceptionPolicy.HandleException(ex, "Business Layer Policy");
if (rethrow){
//throwing the error again to write to page
throw;
}finally{
//Do something
}

No comments: