Hacker News new | ask | show | jobs
by Paul_Diraq 2747 days ago
I think it is perfectly fine that destructors can't throw.

For the rare cases that you need finalizers which might throw I would go for something inspired by pythons with statement.

   WITH(expr , lambda)
expands to(sketch):

   bool _exception_happened=false;
   auto __temp = expr;
   __temp.enter();
   try{
       lambda(__temp)
   }catch(const std::exception & ex){
       exception_happened = true;
       __temp.exit(ex);     
   }
   if (not exception_happened){
      __temp.exit();
   }