C++ Logo

std-proposals

Advanced search

Re: [std-proposals] finally keyword

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sun, 1 May 2022 12:42:15 +0200
On 01/05/2022 12.02, Abdullah Qasim via Std-Proposals wrote:
> Why oppose a good feature??

 - It may not be a good feature to start with.
 - Even a good feature comes with an ongoing maintenance cost,
as any feature does.
 - There are implementations other than Microsoft whose internals
may be materially different. What is easy to implement for one
implementation might be substantially harder for another
implementation.
 - I hope you've read https://isocpp.org/std/submit-a-proposal .
Quote:

"Post an initial brief description of your feature on the std-proposals
mailing list, including especially the problem it solves and alternatives
considered."

The "including especially" parts seem to be missing almost entirely.

Jens


> Finally is already implemented by Microsoft, so implementation difficulty = 0
>
>
>
> *From: *Richard Hodges via Std-Proposals <mailto:std-proposals_at_[hidden]>
> *Sent: *01 May 2022 14:59
> *To: *std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>
> *Cc: *Richard Hodges <mailto:hodges.r_at_[hidden]>
> *Subject: *Re: [std-proposals] finally keyword
>
>
>
>
>
>
>
> On Sun, 1 May 2022 at 10:10, Abdullah Qasim via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]>> wrote:
>
> If exception is thrown, no destructor is called.
>
>
>
> Use a unique_ptr with a custom deleter to act as your "finally" clause. Other languages have it because they don't support RAII.
>
> Here's an example:
>
> template<class Item ,class Deleter>
> auto make_finally(Item* item, Deleter del)
> {
> return std::unique_ptr<Item, Deleter>(item, std::move(del));
> }
>
> extern void do_log(FILE* fp, std::string const& contents);
>
> void append_file(std::filesystem::path const& p, std::string const& line)
> {
> auto fin1 = make_finally(::fopen(p.c_str(), "wb+"), &::fclose);
> try
> {
> do_log(fin1.get(), line);
> }
> catch(...)
> {
> // handle error here
> }
>
> // finally happens here
> }
>
>
>
>
>
> ***MEMORY LEAK ALERT***
>
>
>
> 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] <mailto: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] <mailto: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] <mailto:Std-Proposals_at_[hidden]>
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals <https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals>
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden] <mailto:Std-Proposals_at_[hidden]>
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals <https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals>
>
>
>
>

Received on 2022-05-01 10:42:19