Skip to content

Instantly share code, notes, and snippets.

@domiyanyue
Last active August 10, 2020 02:03
Show Gist options
  • Save domiyanyue/3dd0b0dffb3f61b05f02190b183c49be to your computer and use it in GitHub Desktop.
Save domiyanyue/3dd0b0dffb3f61b05f02190b183c49be to your computer and use it in GitHub Desktop.
RAII example 3
int demo3(){
A *a = new A;
int ra = a -> func();
if(ra == 2) {
try {
B *b = new B;
}
catch (...)
{
delete a;
throw;
}
int rb = b->func();
delete a;
delete b;
return rb;
} else if(ra == 1) {
try {
C *c = new C;
}
catch (...)
{
delete a;
throw;
}
int rc = c->func();
delete a;
delete c;
return rc;
}
delete a;
return ra;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment