Hacker News new | past | comments | ask | show | jobs | submit login

I've looked over what unwind-protect does and to me it doesn't do more than what you can do with a custom RAII like class.

The key thing is that it acts like a wrapper around a try/catch/finally-like block (including other forms of flow control), while allowing you to put arbitrary code in the execute and cleanup portions. You would get the same effect with RAII, most of it would be taken care of for you with the right RAII classes, and if you needed custom code then just write a custom RAII like class or be smart about handling it.

Although the C++ version wouldn't handle C's longjmp and also goto's. But if you use them you're not exactly coding in C++ then.




Not just longjmp and goto, but Objective-C's @throw.

As much as I'm a fan of RAII in C++, it really is a "pure C++" idiom. If a C++ class is needed in Objective-C code that can @throw an NSException, then the C++ cleanup code really has to be invocable explicitly (because the destructor might not be called). For example:

  MyCPlusPlusObject object;
  @try
  {
    ...
  }
  @finally
  {
    object.cleanup();
  }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: