public static class CommandLine.DefaultExceptionHandler<R> extends CommandLine.AbstractHandler<R,CommandLine.DefaultExceptionHandler<R>> implements CommandLine.IExceptionHandler, CommandLine.IExceptionHandler2<R>
ParameterExceptions (invalid user input) is handled like this:
err().println(paramException.getMessage());
paramException.getCommandLine().usage(err(), ansi());
if (hasExitCode()) System.exit(exitCode()); else return returnValue;
ExecutionExceptions that occurred while executing the Runnable or Callable command are simply rethrown and not handled.
| Constructor and Description |
|---|
DefaultExceptionHandler() |
| Modifier and Type | Method and Description |
|---|---|
java.util.List<java.lang.Object> |
handleException(CommandLine.ParameterException ex,
java.io.PrintStream out,
CommandLine.Help.Ansi ansi,
java.lang.String... args)
Handles a
ParameterException that occurred while parsing the command
line arguments and optionally returns a list of results. |
R |
handleExecutionException(CommandLine.ExecutionException ex,
CommandLine.ParseResult parseResult)
This implementation always simply rethrows the specified exception.
|
R |
handleParseException(CommandLine.ParameterException ex,
java.lang.String[] args)
Prints the message of the specified exception, followed by the usage message for the command or subcommand
whose input was invalid, to the stream returned by
CommandLine.AbstractHandler.err(). |
protected CommandLine.DefaultExceptionHandler<R> |
self()
Returns
this to allow method chaining when calling the setters for a fluent API. |
andExit, ansi, err, exit, exitCode, hasExitCode, out, returnResultOrExit, throwOrExit, useAnsi, useErr, useOutpublic java.util.List<java.lang.Object> handleException(CommandLine.ParameterException ex, java.io.PrintStream out, CommandLine.Help.Ansi ansi, java.lang.String... args)
CommandLine.IExceptionHandlerParameterException that occurred while parsing the command
line arguments and optionally returns a list of results.handleException in interface CommandLine.IExceptionHandlerex - the ParameterException describing the problem that occurred while parsing the command line arguments,
and the CommandLine representing the command or subcommand whose input was invalidout - the PrintStream to print help to if requestedansi - for printing help messages using ANSI styles and colorsargs - the command line arguments that could not be parsedpublic R handleParseException(CommandLine.ParameterException ex, java.lang.String[] args)
CommandLine.AbstractHandler.err().handleParseException in interface CommandLine.IExceptionHandler2<R>ex - the ParameterException describing the problem that occurred while parsing the command line arguments,
and the CommandLine representing the command or subcommand whose input was invalidargs - the command line arguments that could not be parsedpublic R handleExecutionException(CommandLine.ExecutionException ex, CommandLine.ParseResult parseResult)
handleExecutionException in interface CommandLine.IExceptionHandler2<R>ex - the ExecutionException describing the problem that occurred while executing the Runnable or Callable commandparseResult - the result of parsing the command line argumentsCommandLine.ExecutionException - always rethrows the specified exceptionprotected CommandLine.DefaultExceptionHandler<R> self()
CommandLine.AbstractHandlerthis to allow method chaining when calling the setters for a fluent API.self in class CommandLine.AbstractHandler<R,CommandLine.DefaultExceptionHandler<R>>