public static interface CommandLine.IExitCodeExceptionMapper
execute
method for an exception that occurred during parsing or while invoking the command's Runnable, Callable, or Method.
Example usage:
@Command class FailingCommand implements Callable<Void> { public Void call() throws IOException { throw new IOException("error"); } } IExitCodeExceptionMapper mapper = new IExitCodeExceptionMapper() { public int getExitCode(Throwable t) { if (t instanceof IOException && "error".equals(t.getMessage())) { return 123; } return 987; } } CommandLine cmd = new CommandLine(new FailingCommand()); cmd.setExitCodeExceptionMapper(mapper); int exitCode = cmd.execute(args); assert exitCode == 123; System.exit(exitCode);
CommandLine.setExitCodeExceptionMapper(IExitCodeExceptionMapper)
Modifier and Type | Method and Description |
---|---|
int |
getExitCode(Throwable exception)
Returns the exit code that should be returned from the
execute method. |