19 Exceptions
19.1 Overview
Commons Math defines a set of exceptions in order to convey the
precise low-level cause of failure.
19.2 Unchecked Exceptions
Starting from version 3.0, all exceptions generated by the
Commons Math code are unchecked (i.e. they inherit from
the standard RuntimeException class).
The main rationale supporting this design decision is that the
exceptions generated in the library are not recoverable: They most
of the time result from bad input parameters or some failure due to
numerical problems.
A thorough discussion of the pros and cons of checked and unchecked
exceptions can be read in
this post by Bruce Eckel.
19.3 Hierarchies
The exceptions defined by Commons Math follow the Java standard
hierarchies:
In all of the above exception hierarchies, several subclasses can
exist, each conveying a specific underlying cause of the problem.
19.4 Features
- Localization
The detailed error messages (i.e. the string returned by the
getLocalizedMessage method) can be localized.
However, besides the American/English default, French is the only language
for which a translation resource is available.
- Exception "context"
Every exception generated by Commons Math implements the
ExceptionContextProvider interface. A call to the
getContext method will return the
ExceptionContext instance stored in the exception, which the
user can further customize by adding messages and/or any object.
|