My boss answered this question why ... (three points) in catch block is exist? quite elegantly.
But it's made me think of something (and hopefully makes up for my previous bad question), does
catch(...){
throw;
}
rethrow the caught exception by value (i.e. a deep copy is taken), or by reference?
Catching by value makes a copy of the exception. But you don't rethrow the copy. You rethrow the original exception that was copied. As such, any modification to the exception caught by value will be lost, including the slicing.
Explanation: Exception handler is used to handle the exceptions in c++.
Hi Shola, yes you can use try / catch without a throw.
The try statement allows you to define a block of code to be tested for errors while it is being executed. The throw keyword throws an exception when a problem is detected, which lets us create a custom error. The catch statement allows you to define a block of code to be executed, if an error occurs in the try block.
The standard says:
A throw-expression with no operand rethrows the currently handled exception. The exception is reactivated with the existing temporary; no new temporary exception object is created.
-- ISO/IEC 14882:2011 Section 15.1 par. 8
In other words, it simply continues the exception propagation with the original exception object. I suppose this is analogous to what you mean by "by reference".
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