Jump to content

Coding by exception

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dtallcott (talk | contribs) at 23:34, 15 May 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Coding by exception is an accidental complexity in a software system in which the program handles specific exceptions that arise . This anti-pattern can quickly degrade software in performance and maintainability.[1]

How to Avoid

As a general rule, well designed software projects contain very few corner cases[2]. There are a variety of software development methodologies that purport to help engineers develop software that avoid these corner cases. They typically address dependency management issues. Design patterns are another tool for arriving at less of a 'one-off' solution. As a simple solution, programmers should avoid writing code to specifically handle an exception and instead use a more generalized solution. Exceptions were invented to inform the user that something went wrong and should be fixed with care.

Accidental Complexity

Accidental complexity is that complexity which arises in computer programs or the development process which is deemed not essential to the problem being solved. Coding by exception is an example of accidental complexity. Where this issue arises from poor planning or programming, some complexity is an essential complexity and unavoidable. Here is a list[3] of accidental complexities:

  • Incorrect Exception Usage
  • Blind Faith
  • Error Hiding
  • Hard Coding
  • Soft Coding
  • Boat Anchor
  • Cargo Cult Programming
  • Magic Number
  • Spaghetti Code
  • Shotgun Surgery

Incorrect Exception Usage

Often coding by exception can lead to further issues in the software with incorrect exception usage. In addition to using exception handling for a unique problem, incorrect exception usage takes this further by executing code even after the exception is raised. This poor programming method resembles the goto method in many software languages but only occurs after a problem in the software is detected.


See also

References