Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

92 C++ Coding Standards 51. Destructors, deallocation, and swap never fail. Summary Everything they attempt shall succeed: Never allow an error to be reported from a destructor, a resource deallocation function (e.g., operator delete), or a swap func- tion. Specifically, types whose destructors may throw an exception are flatly forbid- den from use with the C++ standard library. Discussion These are key functions that must not fail because they are necessary for the two key operations in transactional programming: to back out work if problems are encoun- tered during processing, and to commit work if no problems occur. If there's no way to safely back out using no-fail operations, then no-fail rollback is impossible to im- plement. If there's no way to safely commit state changes using a no-fail operation (notably, but not limited to, swap), then no-fail commit is impossible to implement.