void a(){
int *ptr = new int(10);
throw 1; // throwing after memory allocation
delete ptr;
}
int main(){
try{
a();
} catch(...){
cout << "Exception"<<endl;
}
}
Run Code Online (Sandbox Code Playgroud)
这个程序会导致内存泄漏,有没有办法清除分配的动态内存..?