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:

    The less sophisticated of my forbears avoided foreigners at all costs, for the very good reason that, in their circles, speaking in tongues was commonly a prelude to snake handling. The more tolerant among us regarded foreign languages as a kind of speech impediment that could be overcome by willpower.
    Barbara Ehrenreich (b. 1941)

    I believe, as Maori people do, that children should have more adults in their lives than just their mothers and fathers. Children need more than one or two positive role models. It is in your children’s best interest that you help them cultivate a support system that extends beyond their immediate family.
    Stephanie Marston (20th century)

    I checked out for the last time
    on the first of May;
    graduate of the mental cases,
    with my analyst’s okay,
    my complete book of rhymes,
    my typewriter and my suitcases.
    Anne Sexton (1928–1974)

    ... 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)