Package picocli
Interface CommandLine.IExecutionExceptionHandler
-
- Enclosing class:
- CommandLine
public static interface CommandLine.IExecutionExceptionHandler
Classes implementing this interface know how to handle Exceptions that occurred while executing theRunnable
,Callable
orMethod
user object of the command.Implementation Requirements:
Implementors that need to print messages to the console should use the output and error PrintWriters, and the color scheme from the CommandLine object obtained from the exception.
API Note:
This interface supersedes
CommandLine.IExceptionHandler2
.Example usage:
IExecutionExceptionHandler errorHandler = new IExecutionExceptionHandler() { public int handleExecutionException(Exception ex, CommandLine commandLine, ParseResult parseResult) { //ex.printStackTrace(); // no stack trace commandLine.getErr().println(ex.getMessage()); commandLine.usage(commandLine.getErr()); return commandLine.getCommandSpec().exitCodeOnExecutionException(); } }; int exitCode = new CommandLine(new App()) .setExecutionExceptionHandler(errorHandler) .execute(args);
- Since:
- 4.0
- See Also:
CommandLine.setExecutionExceptionHandler(IExecutionExceptionHandler)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
handleExecutionException(Exception ex, CommandLine commandLine, CommandLine.ParseResult parseResult)
Handles anException
that occurred while executing theRunnable
orCallable
command and returns an exit code suitable for returning fromCommandLine.execute(String...)
.
-
-
-
Method Detail
-
handleExecutionException
int handleExecutionException(Exception ex, CommandLine commandLine, CommandLine.ParseResult parseResult) throws Exception
Handles anException
that occurred while executing theRunnable
orCallable
command and returns an exit code suitable for returning fromCommandLine.execute(String...)
.- Parameters:
ex
- the Exception thrown by theRunnable
,Callable
orMethod
user object of the commandcommandLine
- the CommandLine representing the command or subcommand where the exception occurredparseResult
- the result of parsing the command line arguments- Returns:
- an exit code
- Throws:
Exception
-
-