Tuesday 24 January 2006

I'd rather throw an exception

  • Why throw exceptions? (as opposed to using error codes)
  • When to throw an exception.
  • When not to throw an exception.

Any condition that prevents a method/function from completing its designed objective should result in an exception being thrown. These conditions can arise from invalid input data (a precondition error) or a failure to generate valid output data (return values, class invariants, etc).

For a more complete explanation read:

When and How to Use Exceptions

C/C++ Users Journal August, 2004

A clear, objective, and measurable answer to the question: "When, for what, and how should you use exceptions?"

By Herb Sutter

Read Herb Sutter's Article on CUJ for more information

No comments:

Post a Comment