...
Code Block | ||
---|---|---|
| ||
while (moreToDo) {
SomeType *pst = getNextItem();
try {
pst->processItem();
}
catch (...) {
// deal with exception
throw;
}
delete pst;
}
|
...
Code Block | ||
---|---|---|
| ||
while (moreToDo) {
SomeType *pst = getNextItem();
try {
pst->processItem();
}
catch (...) {
// deal with exception
delete pst;
throw;
}
delete pst;
}
|
...
Wiki Markup |
---|
\[[Meyers 96|AA. C++ References#Meyers 96]\] Item 9: "Use destructors to prevent resource leaks". |
...
RES37-C. Release resources that require paired acquire and release in the object's destructor 08. Memory Management (MEM) 09. Input Output (FIO)RES39-C. Do not use longjmp