antlraux package
v0.2.1

antlraux.clparse
Class ExecutedMethodException

java.lang.Object
  |
  +--java.lang.Throwable
        |
        +--java.lang.Exception
              |
              +--antlraux.clparse.CommandLineParserException
                    |
                    +--antlraux.clparse.ExecutedMethodException
All Implemented Interfaces:
java.io.Serializable

public class ExecutedMethodException
extends CommandLineParserException

This exception is thrown when the method associated to a task launch itself an exception.

For example, consider you have a method like this:

  public class Foo
  {
    public Foo() {}
    public Integer divide(Integer a, Integer b)
    {
       return new Integer(a.intValue()/b.intValue();
    }
  }
  
Method divide will launch a ArithmeticException if b.intValue()==0.

Now consider that you associate a command of the command line to this particular method:

  import antlraux.clparse.*;
  
  public static void main(String [] args)
  {
    Foo executer = new Foo();
    CommandLineParser clp = new CommandLineParser("Main");
    clp.addCommand(executer, "-div", "divide", "ii", "Divide two integers");
    try
    {
       clp.parseWhilePossible();
       clp.executeWhilePossible();
    }catch (CommandLineParserException clpe){
       clpe.printStackTrace(System.err);
    }
  
This program will work very well: if an exception is thrown in Foo.divide(Integuer, Integuer), it will be encapsulated in an ExecutedMethodException, which is a subclass of CommandLineParserException. This way the fact of being able to intercept exceptions launched by the executer are transparent for the majority of users, who don't need this capacity.

In order to work specifically with exceptions launched by the executer, you'll have to capture ExecutedMethodException before capturing CommandLineParserException. This way you can call getException() and get the Exception launched.

  public static void main(String [] args)
  {
    Foo executer = new Foo();
    CommandLineParser clp = new CommandLineParser("Main");
    clp.addCommand(executer, "-div", "divide", "ii", "Divide two integers");
    try
    {
       clp.parseWhilePossible();
       clp.executeWhilePossible();
    } catch (ExecutedMethodException eme){
       Exception e = eme.getException();
       e.printStackTrace(System.err);
    }
    } catch (CommandLineParserException clpe){
       clpe.printStackTrace(System.err);
    }
  }
  

Don't forget that you must capture ExecutedMethodException before capturing CommandLineParserException.

Author:
Enrique José García Cota
See Also:
Serialized Form

Constructor Summary
protected ExecutedMethodException()
           
protected ExecutedMethodException(java.lang.String msg)
           
protected ExecutedMethodException(java.lang.String msg, java.lang.Exception exception)
           
 
Method Summary
 java.lang.Exception getException()
          Method that returns the exception launched by the executed method.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExecutedMethodException

protected ExecutedMethodException()

ExecutedMethodException

protected ExecutedMethodException(java.lang.String msg)

ExecutedMethodException

protected ExecutedMethodException(java.lang.String msg,
                                  java.lang.Exception exception)
Method Detail

getException

public java.lang.Exception getException()
Method that returns the exception launched by the executed method.

Returns:
The exception launched by the executed mehod.

antlraux package
v0.2.1

Created by Enrique José García Cota