Date: Mon, 26 Feb 2024 11:44:30 +0100
Even if you want to clean up by ignoring exceptions for a list of statements, you might want to bulldoze only through certain kinds of exceptions in your exception hierarchy, e.g. a SoftException vs. a HardException.
You also might (as others have mentioned) want to put in logging into the catch block.
The _Bulldoze facility prevents a lot of the existing exception features.
How about instead:
_Bulldoze_try { // very clear that it is not a normal try block
optional<stringstream> ss;
ss.emplace();
if ( ss ) *ss << 77;
if ( ss ) cout << std::move(*ss).str();
} catch(...) // optional specific Exceptions
{
// optional logging
_Bulldoze_continue; // explicit continue
}
_Bulldoze_try allows you to continue within the try-block. You can put in logging, you can make the continue conditional, and so on.
There are many questions in the internet (Stackoverflow and other pages), where people are asking, if one can continue within the try-block instead of after the catch block. Due to stack rewinding it is not possible to continue, where the exception originally occured, but at least, we can continue, where it was caught, can't we?
-----Ursprüngliche Nachricht-----
Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Mo 26.02.2024 09:24
Betreff:Re: [std-proposals] Bulldoze Exceptions
An:std-proposals_at_[hidden];
CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>;
I reply to Tiago and Jan in series below.
On Sun, Feb 25, 2024 at 3:24 PM Tiago Freire wrote:
>
> If I ever saw such a pattern in production code I would be 99.9% that it was bugged even without looking at what else it is doing.
> Clean up code should never fail.
I've seen lots of clean-up code, or finalisation code, over the years
that can throw exceptions, for example it if opens a file for logging,
or if it writes to a database, or if it sends data out on the RS232
port, or even if it just decrements a semaphore. If one part of the
clean-up or finalisation fails, it's better just to get as much
clean-up or finalisation done as possible (i.e. don't neglect to write
to the database just because the RS232 port failed to write).
On Sun, Feb 25, 2024 at 4:17 PM Jan Schultke wrote:
>
> However, that really makes the feature no more powerful than literally
> wrapping everything in a try {...} catch(...) {} block, and you can
> easily do that with a macro already, or by just writing it out.
Yeah that's right, the following code:
{ _Bulldoze:
optional<stringstream> ss;
ss.emplace();
if ( ss ) *ss << 77;
if ( ss ) cout << std::move(*ss).str();
}
is exactly equivalent to:
{ _Bulldoze:
optional<stringstream> ss;
try { ss.emplace(); } catch(...){}
try { if ( ss ) *ss << 77; } catch(...){}
try { if ( ss ) cout << std::move(*ss).str(); } catch(...){}
}
This new feature would not make something possible that was previously
impossible, but it would allow programmers to write simpler, neater
code.
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2024-02-26 10:44:32