 
                            ...
| Code Block | ||||
|---|---|---|---|---|
| 
 | ||||
| #include <new>
 
struct SomeType {
  SomeType() noexcept; // Performs nontrivial initialization.
  ~SomeType(); // Performs nontrivial finalization.
  void process_item() noexcept(false);
};
 
void f() {
  SomeType *pst = new (std::nothrow) SomeType();
  if (!pst) {
    // Handle error
    return;
  }
 
  try {
    pst->process_item();
  } catch (...) {
    // HandleProcess error, but do not recover from it; rethrow.
    throw;
  }
  delete pst;
}
 | 
Compliant Solution (delete)
...
| Code Block | ||||
|---|---|---|---|---|
| 
 | ||||
| #include <new>
struct SomeType {
  SomeType() noexcept; // Performs nontrivial initialization.
  ~SomeType(); // Performs nontrivial finalization.
  void process_item() noexcept(false);
};
void f() {
  SomeType *pst = new (std::nothrow) SomeType();
  if (!pst) {
    // Handle error
    return;
  }
  try {
    pst->process_item();
  } catch (...) {
    // HandleProcess error, but do not recover from it; rethrow.
    delete pst;
    throw;
  }
  delete pst;
} | 
...
| Code Block | ||||
|---|---|---|---|---|
| 
 | ||||
| struct SomeType {
  SomeType() noexcept; // Performs nontrivial initialization.
  ~SomeType(); // Performs nontrivial finalization.
  void process_item() noexcept(false);
};
void f() {
  SomeType st;
  try {
    st.process_item();
  } catch (...) {
    // HandleProcess error, but do not recover from it; rethrow.
    throw;
  } // After re-throwing the exception, the destructor is run for st.
} // If f() exits without throwing an exception, the destructor is run for st.
 | 
...