A have a conceptual question. Consider a C++ function that catches all possible exceptions thrown by code it calls, it looks like
void func() {
try {
// lots of stuff that may throw
} catch(...) {
// handle exceptions, NOTHING here throws.
}
}
My question is: Does this function qualifies as noexcept? And should it be declared as such? I have this doubt because there is a possible exception propagation going on inside it, but caller code will never receive one.
From Exception specifications, Section 15.4/2 of the C++11 standard:
A function with a non-throwing exception-specification does not allow any exceptions.
If the code in the catch block is guaranteed to not throw any exceptions, then the function can have a non-throwing exception-specification. i.e. you may use:
void func() throw () { ... }
or
void func() noexcept { ... }
or
void func() noexcept(true) { ... }
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