Date: Thu, 11 Jan 2024 17:37:51 +0200
On Thu, 11 Jan 2024 at 17:24, Andrey Semashev via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On 1/11/24 17:42, Frederick Virchanza Gotham via Std-Proposals wrote:
> > Today I wrote the following code; look at how I use a stack variable
> > "exception_was_thrown":
> >
> > bool exception_was_thrown = false;
> >
> > try
> > {
> > Entry_Point_Thread_Terminal_Proper(str_comport);
> > rs232win.Close(); // This is harmless no-op if the port isn't open
> > }
> > catch(std::exception const &e)
> > {
> > exception_was_thrown = true;
> > LogText( std::string( "Exception (" ) + e.what() + ")" );
> > }
> > catch(...)
> > {
> > exception_was_thrown = true;
> > LogText("Unknown Exception");
> > }
> >
> > if ( exception_was_thrown )
> > {
> > pdialog->CallAfter(&Dialog_Main::CallTerminateFullRun);
> > }
> >
> > Upon the catching of an exception, I want some common code to be
> > executed for all of the 'catch' clauses.
>
> Why not use a scope guard?
Or just use one catch(...) handler that does the preamble and the
postamble, and calls a helper function
between them, and then do the handling of separate exceptions in that
helper, after rethrowing the
exception, or accessing it via a non-throwing API of exception_ptr
once that proposal makes progress.
<std-proposals_at_[hidden]> wrote:
>
> On 1/11/24 17:42, Frederick Virchanza Gotham via Std-Proposals wrote:
> > Today I wrote the following code; look at how I use a stack variable
> > "exception_was_thrown":
> >
> > bool exception_was_thrown = false;
> >
> > try
> > {
> > Entry_Point_Thread_Terminal_Proper(str_comport);
> > rs232win.Close(); // This is harmless no-op if the port isn't open
> > }
> > catch(std::exception const &e)
> > {
> > exception_was_thrown = true;
> > LogText( std::string( "Exception (" ) + e.what() + ")" );
> > }
> > catch(...)
> > {
> > exception_was_thrown = true;
> > LogText("Unknown Exception");
> > }
> >
> > if ( exception_was_thrown )
> > {
> > pdialog->CallAfter(&Dialog_Main::CallTerminateFullRun);
> > }
> >
> > Upon the catching of an exception, I want some common code to be
> > executed for all of the 'catch' clauses.
>
> Why not use a scope guard?
Or just use one catch(...) handler that does the preamble and the
postamble, and calls a helper function
between them, and then do the handling of separate exceptions in that
helper, after rethrowing the
exception, or accessing it via a non-throwing API of exception_ptr
once that proposal makes progress.
Received on 2024-01-11 15:38:05