#include
using std::cout;
using std::endl;
#include
// throw an exception
void g() {
bool some_condition = false;
if (some_condition == false)
throw "Any exception";
}
void func() {
string * pstr = new string;
g(); //memory leak if g throws an exception
delete pstr; //unreachable code if g() throws
}
int main() {
try {
func();
} catch(...) {
cout << "exiting with a memory leak" << endl;
}
}