Wednesday, October 21, 2009

ExceptionListener Interface



















Chapter 12 - Exception Callback

Java Thread Programming
Paul
Hyde






size=1>  size=2>Copyright � 1999 Sams
Publishing




















size=4>ExceptionListener Interface












size=2>Classes that want to be notified when an exception occurs in
an active class can implement the
face="Courier New" size=2>ExceptionListener color=#010100 face=Arial size=2> interface shown in Listing
12.1.












size=2>Listing 12.1  ExceptionListener.java—The Interface to
Be Implemented for Exception Callback












face="Courier New" size=2>1: public interface ExceptionListener
{










face="Courier New" size=2>2:     public void
exceptionOccurred(Exception x, Object source);










face="Courier New" size=2>3: }












size=2>This interface declares that classes of the type color=#010100 face="Courier New"
size=2>ExceptionListener
size=2> must implement an face="Courier New" size=2>exceptionOccurred() color=#010100 face=Arial size=2> method. An active class will invoke
this method on the listener whenever a notable exception should be
relayed. The first parameter,
face="Courier New" size=2>x size=2>, is a reference to the actual exception. The second
parameter,
size=2>source, is a
reference to the active class that caught the exception. Having a
reference to the
size=2>source object
allows one
size=2>ExceptionListener size=2> to monitor more than one active object and take a different
course of action for each object monitored. If this is not
necessary, the
size=2>source parameter
can simply be ignored.












valign="top" bgcolor="#FFFFFF">

Toc



No comments: