C++ Tips: Difference between revisions

Jump to navigation Jump to search
399 bytes added ,  19 October 2009
no edit summary
No edit summary
No edit summary
Line 74: Line 74:


* Do ''not'' catch all exceptions via <tt>catch (...)</tt> - this can mask real problems. Better granularity of exception handling does require some clean-ups to the hierarchy, so catchable / ignorable errors can be distinguished from fatal ones, but in the mean time, the safest policy is to let the main loop catch and report the exception, or to catch yourself and then re-throw.
* Do ''not'' catch all exceptions via <tt>catch (...)</tt> - this can mask real problems. Better granularity of exception handling does require some clean-ups to the hierarchy, so catchable / ignorable errors can be distinguished from fatal ones, but in the mean time, the safest policy is to let the main loop catch and report the exception, or to catch yourself and then re-throw.
* Make ownership of objects passed into / out of functions and methods explicit, where possible. This can be done via naming, documentation, use of shared pointers, ref-counted pointers or <tt>std::auto_ptr</tt>, to name a few possibilities. It's always better to ensure a method can only be called the 'right' way, rather than trying to document the intended behaviour and hope people respect it.
580

edits

Navigation menu