Date: Mon, 26 Feb 2024 13:58:04 +0000
On Mon, Feb 26, 2024 at 10:44 AM Sebastian Wittmeier wrote:
>
> _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?
So if the line "ss.emplace()" were to throw an exception, then it
would enter the 'catch' block, and then when it hits
"_Bulldoze_continue", it goes back into the try-block and continues at
the next line (i.e. "if (ss) *ss << 77;"), do I understand correctly?
To make things more simple, we could forbid the defining of variables
inside the try-block, and so you would have to define all variables
before the try-block is entered:
optional<stringstream> ss;
_Bulldoze_try
{
ss.emplace();
if ( ss ) *ss << 77;
if ( ss ) cout << std::move(*ss).str();
}
That would simply the implementation quite a bit.
>
> _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?
So if the line "ss.emplace()" were to throw an exception, then it
would enter the 'catch' block, and then when it hits
"_Bulldoze_continue", it goes back into the try-block and continues at
the next line (i.e. "if (ss) *ss << 77;"), do I understand correctly?
To make things more simple, we could forbid the defining of variables
inside the try-block, and so you would have to define all variables
before the try-block is entered:
optional<stringstream> ss;
_Bulldoze_try
{
ss.emplace();
if ( ss ) *ss << 77;
if ( ss ) cout << std::move(*ss).str();
}
That would simply the implementation quite a bit.
Received on 2024-02-26 13:58:17