Java Reference
In-Depth Information
try
{
//code
}
catch( Exception e )
{
e.printStackTrace();
}
You can see the drawbacks of this approach. Imagine you are using management
software to configure the PropertyManager MBean you created in section 4.3.1.
You create that MBean by specifying a path to a properties file. During construc-
tion, the MBean attempts to open a file with that path and load it into a proper-
ties object. If that file does not exist, an exception is thrown and basically
ignored. From the management tool, you would never know what had occurred,
and your application's configuration would be in error.
To adequately manage an application, you must know if your management
actions succeed or cause errors. Fortunately, JMX provides a way to avoid the sit-
uation we just described, by supporting runtime and declared exceptions.
Declared exceptions are declared in a throws statement. Runtime exceptions are
not expected and are not required to be in a try-catch statement.
Exceptions in JMX occur in two categories. First, exceptions occur as agent-
level components (such as MBeanServer ) perform operations on an MBean. For
example, registration, lookup, and invoking methods on an MBean instance fall
into this category. Second, exceptions occur as defined by MBean code. These
include Java language exceptions and user-defined exceptions.
JMX supports a mechanism for handling exceptions in a meaningful way. The
last sections of this chapter discuss exceptions at the MBean level.
4.5.1
Throwing exceptions
Figure 4.10 depicts the class hierarchy for JMX exceptions. The main class is
JMException ; all others are subclasses of it. It has three subclasses: OperationsEx-
ception , ReflectionException , and MBeanException . Each of these exception
types has subclasses, as well.
Yo u c a n s e e t h a t JMX exceptions at the MBean level are broken down into
three categories, extending from one of three super classes:
OperationsException —Subclasses define exceptions that occur when
invoking operations on an MBean.
ReflectionException —Wraps standard reflection exceptions of the Java
language that occur when working with MBean classes.
Search WWH ::




Custom Search