Re-throwing exceptions When an exception is cached in a catch block, you can re-throw it using the throw keyword (which is used to throw the exception objects).
If a catch block ends normally, without a throw , the flow of control passes over all other catch blocks associated with the try block. Whenever an exception is thrown and caught, and control is returned outside of the function that threw the exception, stack unwinding takes place.
It's fine practice to throw in the catch block. It's questionable practice to do so ignoring the original exception.
It's passing the exception up to the next handler. If there is a try... catch block around the method call in which the exception is caught and thrown, it will be picked up and processed by that handler instead.
I just stumbled this code:
void somefunction() { throw; }
and I wonder: what does it mean?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With