czw., 11 sty 2024 o 16:42 Arthur O'Dwyer via Std-Proposals <std-proposals@lists.isocpp.org> napisał(a):
>
> Right. You can do this pretty naturally using the `Auto` macro, for example:
> https://godbolt.org/z/b5zvKPb61
> The only trick is that the way to express "Do `OnTheWayOut` at the end of every catch-block" is really to express "Do an early exit at the end of the try block, and then let all the catch blocks fall through into `OnTheWayOut`." That's not as structured as we'd really like, but it's okay.
>
> void test(int x) {
> printf("Testing with x=%d\n", x);
> try {
> Auto(
> if (std::uncaught_exceptions() >= 1)
Was this incorrect when `test` is called inside of another `catch`?
At least for normal function (not coroutines) you should compare
```
if (old_uncaught_exceptions < std::uncaught_exceptions()) { /* do something */ }
```
Ah, yes. I wasn't thinking that this particular bit of code could possibly be called during stack unwinding; but if it could, then absolutely, you're right.
Just for the record, with `Auto` that would look like
try {
int n = std::uncaught_exceptions();
Auto(
if (std::uncaught_exceptions() > n)
puts(" CallTerminateFullRun");
);
puts(" In try body");
–Arthur