Hacker News new | ask | show | jobs
by iam 4422 days ago
This definitely dampens the usefulness.

It's like the author knew it was a bad idea too (he put noexcept(false) on the destructor; without which in C++11 the program terminates immediately when an exception is thrown from destructor).

If there's some way to avoid terminating when there's a double exception in the destructor, that would be good to hear!

One simple way I can think of is to reuse the same variable instead.

   ThrowOnError throw_on_error;
   std::cout << libfoo_create_widgets(1, &c1, throw_on_error) << libfoo_create_widgets(2, &c2, throw_on_error);
1 comments

This will not work, as `throw_on_error` is not going to be destroyed at the end of the printing statement. Sure, you could wrap the whole thing up into a local scope, but as this trick was invented to save a couple of lines of vertical space, the usefulness of doing it seems little.