Throw versus ThrowEx

 

 

When you intercept exceptions( for logging ) you can

 
catch (Exception ex)
            {
                //TODO: log : 
                //https://youtu.be/OvzcBTm3Sow
                string s = ex.Message;
                throw ex;
            }
 

or

 
catch (Exception ex)
            {
                //TODO: log : 
                //https://youtu.be/OvzcBTm3Sow
                string s = ex.Message;
                throw ;
            }

The difference is small – but the consequences are losing the original stack trace , if you

 throw ex; 

I have done a small video about this : https://youtu.be/Deigld3Bqko

I have not covered ExceptionDispatchInfo  that you can see an usage here: http://blogs.microsoft.co.il/sasha/2011/10/19/capture-transfer-and-rethrow-exceptions-with-exceptiondispatchinfo-net-45/