Hi,

but why? You have RAII, use it. It's the proper way to deal with resource cleanup.

struct _finally()
{
  _finally(std::function<void(void)> f) _f(f) : {}
  ~_finally() ( _f(); };
  std::function<void(void)> _f;
};

my_function() {
  // let's define our finally
  _finally f([](){
       cleanup();
  });

  try {
  } catch(...) {}
  // whatever.
  
} // here your _finally will be destroyed, which will call the d'tor ~_finally() and your lambda in d'tor will be called.
But this is a lazy bodge. You could nicely encapsulate your resource as a class and get RAII out of the box.

BR,
Igor


Am So., 1. Mai 2022 um 09:52 Uhr schrieb Abdullah Qasim via Std-Proposals <std-proposals@lists.isocpp.org>:

 

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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals