Skip to content

Instantly share code, notes, and snippets.

@castaneai
Created December 21, 2015 02:40
Show Gist options
  • Select an option

  • Save castaneai/f7b2d6d13454524eed0d to your computer and use it in GitHub Desktop.

Select an option

Save castaneai/f7b2d6d13454524eed0d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <memory>
using namespace std;
struct A {
void release() { cout << "Release!!" << endl; }
};
struct deleter { void operator()(A* a) { a->release(); } };
unique_ptr<A, deleter> f()
{
unique_ptr<A, deleter> ptr;
throw exception("exception");
return move(ptr);
}
int main(void)
{
try {
auto t = f();
}
catch (const exception& ex) {
cout << ex.what() << endl;
}
catch (...) {
throw;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment