When a exception is caught and it is necessary to process the exception and rethrow it, then statement throw can be used.
If it is necessary to throw new exception:
tryIf it is necessary to throw caught exception next:
{
throw exp;
}
catch (Exception e)
{
Debug.Write(e.Message); // Exception processig
throw new Exception("DoException", e);
}
try
{
throw exp;
}
catch (Exception e)
{
Debug.Write(e.Message); // Exception processig
throw;
}
First code will generate exception System.Exception and second code will generate exception exp (in our test sample Exception1).
Console output:
All sources can be download from google code project csharp-tips "google code" project
1 comment:
http://www.aired.in/2009/06/c-questions-on-exception-handling-and.html
Post a Comment