C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Common code for all exceptions thrown

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Thu, 11 Jan 2024 18:23:51 +0300
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?

Received on 2024-01-11 15:23:55