Created
December 21, 2015 02:40
-
-
Save castaneai/f7b2d6d13454524eed0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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