Yes, sorry. h(g(f(x))) was not meant as a C++ expression, but how the function call each other.
In full notation it would be:
// f throws an exception
int f(int x) {
throw std::exception();
return x * x;
}
// g does not have to care
int g(int x) {
return 4 * f(x);
}
// h catches the exception
int h(int x) {
try {
int y = g(x);
} catch(const std::exception& e)
{
// handle it
}
return y + 2;
}
-----Ursprüngliche Nachricht-----
Von: Rainer Deyke via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Fr 28.08.2026 14:16
Betreff: Re: [std-proposals] fine-control exception/error/UB handling on function boundary
An: std-proposals@lists.isocpp.org;
CC: Rainer Deyke <rainerd@eldwood.com>;
On 8/28/26 12:08, Sebastian Wittmeier via Std-Proposals wrote:
> h(g(f()))
>
>
> One important philosophy of exceptions is that code in-between - like the function g - does not have to care, what kind of exceptions are thrown by f, as long as h handles it.
Neither g nor h will ever see the exception if f throws. Neither g nor
h have the opportunity to handle the exception. Neither g nor h will
even be called.
--
Rainer Deyke - rainerd@eldwood.com
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals