throwing new exceptions in catch()
I'm trying to catch an exception, add information to it, and throw a new
(enhanced) exception for the calling module.
Example:
void CallingMethod()
{
try
{
doStuff();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
void doStuff()
{
try
{
// do something here that may throw an error
}
catch(Exception e)
{
Exception e2 = new Exception("new added info", e);
throw e2;
}
finally()
{
// cleanup
}
}
but when the error occurs and is written to the console, it is the
original error not my new error containing the string "new added info".
Is this expected? How should I throw a new error to be caught?
No comments:
Post a Comment