Difference between throw; & throw ex; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Difference between throw; & throw ex;

could anyone simple explain mentioned difference between throw and throw ex? i know that its connected with stack trace. thanks

31st May 2017, 12:50 PM
Mateusz Byczkowski
Mateusz Byczkowski - avatar
1 Answer
+ 1
"throw ex throws the same exception, but resets the stack trace to that method. Unless you want to reset the stack trace (i.e. to shield public callers from the internal workings of your library), throw is generally the better choice, since you can see where the exception originated." https://stackoverflow.com/questions/730250/is-there-a-difference-between-throw-and-throw-ex
31st May 2017, 2:48 PM
Eranga
Eranga - avatar