> From: Berin Loritsch [mailto:[EMAIL PROTECTED]]
>
> void addLoggerListener( final LoggerListener listener )
> throws java.util.TooManyListenersException()
> {
> if ( null == m_loggerListener )
> {
> m_loggerListener = listener;
> }
> else
> {
> throw new java.util.TooManyListenersException();
> }
> }
+1
> * Easy to do, does not change functionality
> * Clearer contract, although it forces client code to do exception
> handling for the listener.
> * No future API changes other than the removal of the declared
exception
Will result in compilation errors. Given a:
try {
x.addLoggerListener (this);
} catch (TooManyListenersException tmle) {
// Do nothing
}
if addLoggerListener (this) doesn't throw a TooManyListenersException,
javac will complain that "TooManyListenersException not thrown in
corresponding try clause".
I suggest a:
synchronized void addLoggerListener( final LoggerListener listener )
throws java.lang.UnsupportedOperationException
{
if ( null == m_loggerListener )
{
m_loggerListener = listener;
}
else
{
throw new java.lang.UnsupportedOperationException("This version
of LogKit (1.2) doesn't support multicast listeners.");
}
}
as UnsupportedOperationException is a RuntimeException and requires no
try/catch,
plus we get the protection of an exception when some code is fighting
over who
gets to be the listener for an attractive logger.
/LS
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]