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)

    The interest in Wisdom is fading. Soon there will not be enough left to support the aphorism, even though it tries to amuse by half-mocking the Wisdom it propounds.
    Mason Cooley (b. 1927)

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

    For true poetry, complete poetry, consists in the harmony of contraries. Hence, it is time to say aloud—and it is here above all that exceptions prove the rule—that everything that exists in nature exists in art.
    Victor Hugo (1802–1885)