C++ Logo

std-proposals

Advanced search

Re: [std-proposals] finally keyword

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Sun, 1 May 2022 12:19:02 +0300
On 5/1/22 10:52, Abdullah Qasim via Std-Proposals wrote:
>
>
> try|{|
>
> | |something|();|
>
> |} |catch|(...) {|
>
> | std::cerr << |"exception caught!!"|;|
>
> |}|
>
> | |
>
> |std::clog << |"No except caught!"|;|
>
> | |
>
> |finally { |// already Microsoft extension, but||
>
> | |cleanup|(); // |should be in core language||
>
> |}|

First, please know that introducing new keywords is always problematic.
The keyword may already be used in written code, which will break it.
Whenever you propose to introduce a new keyword, you should research the
currently written code base as to whether it is already used there. Or
just reuse an existing keyword, like `final` for example.

Second, in the form you presented the extension wouldn't work or would
be difficult or unsafe to use. Does the body of the final block have
access to the variables declared since the last `catch` clause? If yes,
what will be their value if the function exits before they are initialized?

Microsoft does not allow this. Their `__try`/`__finally` extension, if
that is what you refer to, explicitly connects the block that is guarded
with the final block, i.e. the final block only has access to the
variables declared before the `__try` block.

Also, I'm not in favor of the Microsoft's extension, as it visually
moves the final handler to the bottom.

Received on 2022-05-01 09:19:06