C++ Logo

std-proposals

Advanced search

Re: [std-proposals] finally keyword

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sun, 1 May 2022 11:10:45 +0200
On 01/05/2022 10.09, Abdullah Qasim via Std-Proposals wrote:
> If exception is thrown, no destructor is called.

This is not accurate. See [except.ctor] in the standard.

> ***MEMORY LEAK ALERT***

No, destructors is the way to reliably avoid memory leaks.
See unique_ptr and shared_ptr for examples.

More reading:

https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization

Jens


> Finally is used for tasks performed regardless of thrown exception, but when exception is caught, control jumps to finally block.
>
>
>
> Useful!
>
>
>
> *From: *Peter C++ via Std-Proposals <mailto:std-proposals_at_[hidden]>
> *Sent: *01 May 2022 13:04
> *To: *std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>
> *Cc: *Peter C++ <mailto:peter.cpp_at_[hidden]>
> *Subject: *Re: [std-proposals] finally keyword
>
>
>
> that is a feature what destructors and SBRM are fir
>
>
>
> available in standard library extensions TS2, as scope guards, but not approved to std for the better.(I am the author)
>
>
>
> if there is a simple enough library solution, why should there be a language extension.
>
>
>
> watch a recording of one of my "what classes we design and how" to learn when destructors and clean up are actually desirable.
>
> sent from a mobile device so please excuse strange words due to autocorrection.
>
> Peter Sommerlad
>
> peter.cpp_at_[hidden]
>
> +41-79-432 23 32
>
>
>
> On 1 May 2022, at 09:52, Abdullah Qasim via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> 
>
>
>
> try|{|
>
> | |something|();|
>
> |} |catch|(...) {|
>
> | std::cerr << |"exception caught!!"|;|
>
> |}|
>
> | |
>
> |std::clog << |"No except caught!"|;|
>
> | |
>
> |finally { |// already Microsoft extension, but
>
> | |cleanup|(); // |should be in core language
>
> |}|
>
>
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
>
>
>

Received on 2022-05-01 09:10:49