Exception chaining

Exception chaining

Exception chaining, or exception wrapping, is an object-oriented programming technique of handling exceptions by re-throwing a caught exception after wrapping it inside a new exception. The original exception is saved as a property (such as "cause") of the new exception. The idea is that a method should throw exceptions defined at the same abstraction level as the method itself, but without discarding information from the lower levels.

"For example, a method to play a movie file might handle exceptions in reading the file by re-throwing them inside an exception of movie playing. The user interface doesn't need to know whether the error occurred during reading chunk of bytes, trying eof() or whatever, and was it unexpected end of file, read error or whatever reading error: it needs only exception message extracted from "cause". The user interface layer will have its own set of exceptions. The one interested in "cause" can see its stack trace during debugging or in proper log."

Throwing the right kind of exceptions is particularly enforced by checked exceptions in the Java programming language, and starting with language version 1.4 all exceptions support chaining.

In runtime engine environments such as Java or .Net there exist tools that attach to the runtime engine and every time that an exception of interest occurs they record debugging information that existed in memory at the time the exception was thrown (stack and heap values). These tools are called Exception Interception and they provide 'root-cause' information for exceptions in Java programs that run in production, testing or development environments.

References

* [http://www.javaworld.com/javaworld/jw-09-2001/jw-0914-exceptions.html "Exceptional practices"] by Brian Goetz at javaworld.com


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Exception handling — is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution. Programming languages differ considerably in their support… …   Wikipedia

  • Cipher Block Chaining — Mode d opération (cryptographie) En cryptographie, un mode d opération est la manière de traiter les blocs de texte clairs et chiffrés au sein d un algorithme de chiffrement par bloc. Chacun des modes possède ses propres atouts. Plusieurs modes… …   Wikipédia en Français

  • Comparison of C Sharp and Java — The correct title of this article is Comparison of C# and Java. The substitution or omission of the # sign is because of technical restrictions. Programming language comparisons General comparison Basic syntax Basic instructions …   Wikipedia

  • Comparison of Java and C Sharp — This is a comparison of the C# programming language with the Java programming language. As the two are both garbage collected runtime compiled languages with syntax derived from C and C++, there are many similarities between Java and C#. However …   Wikipedia

  • Java version history — The Java language has undergone several changes since JDK 1.0 as well as numerous additions of classes and packages to the standard library. Since J2SE 1.4, the evolution of the Java language has been governed by the Java Community Process (JCP) …   Wikipedia

  • Java (software platform) — Not to be confused with JavaScript. Java Original author(s) Oracle Corporation Developer(s) James Gosling / Sun Microsystems …   Wikipedia

  • BMT Canarsie Line — The Canarsie Line (sometimes referred to as the 14th Street ndash;Canarsie Line) is a rapid transit line of the BMT Division of the New York City Subway system, named after its terminus in the Canarsie neighborhood of Brooklyn. It is used by the… …   Wikipedia

  • ABAP — Infobox programming language name = ABAP/4 logo = paradigm = Object oriented, structured, imperative year = 1980s designer = SAP AG typing = Static, strong, safe, nominative implementations = SAP R/2,SAP R/3 dialects = influenced by = Objective C …   Wikipedia

  • CBC (cryptographie) — Mode d opération (cryptographie) En cryptographie, un mode d opération est la manière de traiter les blocs de texte clairs et chiffrés au sein d un algorithme de chiffrement par bloc. Chacun des modes possède ses propres atouts. Plusieurs modes… …   Wikipédia en Français

  • Europe, history of — Introduction       history of European peoples and cultures from prehistoric times to the present. Europe is a more ambiguous term than most geographic expressions. Its etymology is doubtful, as is the physical extent of the area it designates.… …   Universalium

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”