Exceptions · interview question
Inside a catch (Exception ex) block, what's the difference between throw; and throw ex;?
Multiple choiceMedium
Answer and explanation
Correct answer
A. throw; preserves the original stack trace; throw ex; resets it to the current line.
Why
Use throw; to rethrow. If you need to add context, wrap it: throw new OrderException("...", ex); keeps the original as InnerException.
Test yourself on Exceptions
A free test with instant, explained results. No account needed.