mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <elecha...@apache.org>
Subject Is the ExceptionMonitor usefull ?
Date Thu, 03 Jul 2008 16:46:16 GMT
Hi guys,

I'm currently spending some time documenting the AbstractIoService 
class, where the ExceptionMonitor instance is created. This class is 
just used to handle exception when they are uncaught :

 * Monitors uncaught exceptions.  {@link #exceptionCaught(Throwable)} is
 * invoked when there are any uncaught exceptions.
public abstract class ExceptionMonitor {

At least, this is what the Javadoc says ... But in fact, 'uncaught 
exception' does not make a lot of sense. Either we catch an exception, 
or not. If we don't catch it, there is no way to deal with it as an 
uncaught exception, because otherwise, it means it has been caught, and 
is not anymore uncaught ... :/

There is soemthing wrong in this logic. All over the code, we see things 
like :

try {
} catch (Throwable t) {

Assuming that we are using the DefaultExceptionMonitor, this will simply 
log a warning in some log :

public class DefaultExceptionMonitor extends ExceptionMonitor {
    private final Logger log = 

    public void exceptionCaught(Throwable cause) {
        if (log.isWarnEnabled()) {
            log.warn("Unexpected exception.", cause);

Why don't we simply write :
try {
} catch (Throwable t) {
    log.warn("Unexpected exception.", t);


Now, the question is why do we allow a user to define it's own 
ExceptionMonitor to handle unhandled exceptions. As we are defining a 
framework, it does not make a lot of sense to disregard an exception and 
let the user define what to do with it, as the user will have _no clue_ 
about where those kind of exception might be produced (our users are not 
all supposed to go through MINA code).

So do we really need this class ? IMHO, this is a bad idea which has not 
been removed from the very first version (it comes far away : the class 
has been injected back in 2005, and was never derived since, if we 
except the default implementation.

wdyt ?

cordialement, regards,
Emmanuel L├ęcharny

View raw message