Chapter 15. Exception Handling

Table of Contents

Runtime Exceptions
Static Exceptions

A programmer who makes use of the Tensegrity API expects it to behave in a predictable way. In the Java programming language, throwing exceptions is the preferred way of reporting unusual behaviour caused when invoking a method. The Tensegrity API therefore defines a set of unique exception classes which report such error conditions. Java® distinguishes between runtime exceptions and static exceptions.

Runtime Exceptions

Runtime exceptions are dynamic exceptions and do not need to be declared at compile time because they are recognized as such by their superclasses. All dynamic exceptions are subclasses of java.lang.RuntimeException . These exceptions are not necessarily part of a method's signature.

All dynamic exceptions thrown by the Tensegrity API are subclasses of the custom exception com.tensegrity.generic.util.DynamicException . This convention allows users to distinguish between exceptions which are thrown by the Tensegrity API and all other runtime exceptions. To give you an idea as to which runtime exceptions are implemented in the current version of the Tensegrity API, the following table lists all exception classes which extend class com.tensegrity.generic.util.DynamicException:

Table 15.1. Exceptions extending DynamicException

ExceptionDescription
AssertException

Thrown when an assertion check fails.

CustomConstraintException

Thrown when a CustomConstraint cannot be applied or if it is not registered.

DynamicAttributeException

Thrown when an exception involving an Attribute is detected.

GraphDynamicException

This represents the base exception class for graphs.

IllegalElementException

Thrown by an iterator if an ArrayList utility class is accessed out-of-bounds.

InvalidArgumentException

Thrown whenever an invalid argument is passed to a method, including constructors.

ListModifiedException

Thrown if an ArrayList iterator detects that someone else has concurrently modified a container. The concurrent modification checking is fail-fast and not synchronized. Thus it is not reliable.

MathDynamicException

Thrown if mathematical calculations have to be interrupted, for example resulting from a division by zero.

PreferenceException

Thrown whenever an error occurs while working with Preferences.

RuleDynamicException

Thrown if a rule operation fails.

UnsupportedMethodException

Thrown if the called method is not implemented by the receiving object.

VisualSubgraphUnchangedNotificationException

Thrown by a DefaultVisualGraph to notify a Subgraph about denied add/remove node operations.

XMLParseException

Thrown when an XMLReader encounters an exception while parsing a document.

Catching exceptions thrown from the Tensegrity API is a simple task. A “lazy programmer” may choose to only catch the basic runtime exceptions and extract the associated exception messages or propagate the exception type by using the getClass() method of the exception. This is not a recommended practice, however, but may save additional typing effort when writing unit tests or other nonproduction code.