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.
The exceptions defined by Commons Math follow the Java standard hierarchies:
IllegalArgumentException:
A
MathIllegalArgumentException is thrown when some input
parameter fails a precondition check.
IllegalStateException:
A
MathIllegalStateException is thrown when some inconsistency
has been detected.
ArithmeticException:
A
MathArithmeticException is thrown when conditions such as
"division by zero" or "overflow" are encountered.
UnsupportedOperationException:
A
MathUnsupportedOperationException indicates that a feature
is missing or does not make sense in the given context.
In all of the above exception hierarchies, several subclasses can exist, each conveying a specific underlying cause of the problem.
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.
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.
Copyright © 2003-2024 The Apache Software Foundation. All Rights Reserved.