Tuesday, 24 March 2015

Difference between throw ex vs throw


Just had a 5 min before my VS finish building solution


Examples 

try {
DivByZero();
} catch (Exception ex){
throw;
}

try {
DivByZero();
} catch (Exception ex){
throw ex;
}



The difference is:

"throw ex"
  Resets the stack trace (so your errors would appear to originate from location where the code is throwing ex)
"throw"
 Keeps the original stack trace would be preserved.