As you've already been told everything after the throw is not eveluated
anymore, instead the next exception handler kicks in. If you don't have
another exception handler protecting the code you posted somewhere higher in
the call stack of your application, the CLR will handle the exception for
you.
Judging by the return statement your intent seems to be to handle the
exception and continue normally. In that case you do not throw another
exception, you just catch and take the error message:
string errMsg=null;
try
{
MyFunction();
}
catch(Exception e)
{
//
errMsg = "MyFunction failed and this is the lame excuse it returned: " +
e.Message;
}
return errMsg;
If you do want to toss the exception on to the next level and you have some
code after MyFunction() that needs to be executed regardless the success of
MyFunction you may add a finally clause:
string errMsg=null;
try
{
MyFunction();
}
catch(Exception e)
{
// this will only run in case MyFunction throws an exception
errMsg = "MyFunction failed and this is the lame excuse it returned: " +
e.Message;
// throw new Exception("rethrow", e);
}
finally
{
// this will always run, with or without a rethrow
;
}
// this will not run if an exception is rethrown
return errMsg;