|
antlraux package v0.2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Throwable | +--java.lang.Exception | +--antlraux.clparse.CommandLineParserException | +--antlraux.clparse.ExecutedMethodException
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); } }
ExecutedMethodException
before capturing CommandLineParserException
.
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 |
protected ExecutedMethodException()
protected ExecutedMethodException(java.lang.String msg)
protected ExecutedMethodException(java.lang.String msg, java.lang.Exception exception)
Method Detail |
public java.lang.Exception getException()
|
antlraux package v0.2.1 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |