Error Hiding - Manifestations in Languages That Support Checked Exceptions

Manifestations in Languages That Support Checked Exceptions

Error hiding is one of the more common anti-patterns to encounter in languages that support the paradigm of checked exceptions including Java. This type of exception forces the programmer to handle the exception even if the programmer has no means to effectively do so. The problem becomes more egregious in large or complex systems. For example, a programmer implementing function A may require the service of another component B. Component B may then in turn delegate to component C to fulfill that request. If component C encounters a failure during that service it may indicate this by throwing a checked exception to component B. Component B after recovering from the error but unable to fulfill the request from Function A may indicate this by re-throwing the error from C. Function A, having no recourse to handle an error from component C has three options:

  1. Re-throw the exception
  2. Catch the exception, log it and re-throw it
  3. Catch the exception but do nothing meaningful with it.

A novice programmer may choose the third option and hide the error (also referred to as exception swallowing). The consequence of swallowing the exception is that the system may be put into an unstable state but its users (both human and machine) will remain unaware that a critical failure has occurred. These type of errors when finally discovered are sometimes near impossible to debug because when it does manifests as a noticeable error it is sometimes much later in the process from where the error actually occurred.

Given a large multi-layered application with a high amount of inter-object communication checked exceptions may end up being passed through multiple layers before finally reaching a point where they can be properly handled and reported the end user. In addition to being subject to potential hiding issues at each layer, domain models also become polluted with excessive coupling.

For this reason, version 1.4 and later of Java support exception chaining for all exceptions.

Read more about this topic:  Error Hiding

Famous quotes containing the words languages, support, checked and/or exceptions:

    Wealth is so much the greatest good that Fortune has to bestow that in the Latin and English languages it has usurped her name.
    William Lamb Melbourne, 2nd Viscount (1779–1848)

    The sceptics assert, though absurdly, that the origin of all religious worship was derived from the utility of inanimate objects, as the sun and moon, to the support and well-being of mankind.
    David Hume (1711–1776)

    Have you checked the children yet?
    Fred Walton, U.S. screenwriter. Curt Duncan (Tony Beckley)

    ... people were so ridiculous with their illusions, carrying their fools’ caps unawares, thinking their own lies opaque while everybody else’s were transparent, making themselves exceptions to everything, as if when all the world looked yellow under a lamp they alone were rosy.
    George Eliot [Mary Ann (or Marian)