Skip to content

Package io.github.qishr.cascara.common.util

Class DefaultExceptionHandler

java.lang.Object
        io.github.qishr.cascara.common.util.CommandLine.AbstractHandler
                io.github.qishr.cascara.common.util.CommandLine.DefaultExceptionHandler

All Implemented Interfaces:
    IExceptionHandler, IExceptionHandler2

Enclosing Class:
    io.github.qishr.cascara.common.util.CommandLine


public static class DefaultExceptionHandler
extends io.github.qishr.cascara.common.util.CommandLine.AbstractHandler

Default exception handler that handles invalid user input by printing the exception message, followed by the usage message for the command or subcommand whose input was invalid.

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 Summary

Constructor Description
DefaultExceptionHandler()

Method Summary

Modifier and Type Method Description
public List<Object> handleException(ParameterException ex, PrintStream out, Ansi ansi, String[] args)
public R handleParseException(ParameterException ex, 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 #err().
public R handleExecutionException(ExecutionException ex, ParseResult parseResult) This implementation always simply rethrows the specified exception.
protected DefaultExceptionHandler self()

Methods inherited from AbstractHandler

err, andExit, returnResultOrExit, colorScheme, ansi, useAnsi, throwOrExit, hasExitCode, exit, useOut, exitCode, out, useErr

Method Details

handleException

public List<Object> handleException(ParameterException ex, PrintStream out, Ansi ansi, String[] args)

Specified By:

IExceptionHandler


handleParseException

public R handleParseException(ParameterException ex, 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 #err().

Parameters:

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 invalid

args - the command line arguments that could not be parsed

Returns:

the empty list

Specified By:

IExceptionHandler2

Since:

3.0


handleExecutionException

public R handleExecutionException(ExecutionException ex, ParseResult parseResult)

This implementation always simply rethrows the specified exception.

Parameters:

ex - the ExecutionException describing the problem that occurred while executing the Runnable or Callable command

parseResult - the result of parsing the command line arguments

Returns:

nothing: this method always rethrows the specified exception

Specified By:

IExceptionHandler2

Since:

3.0


self

protected DefaultExceptionHandler self()

Overrides:

AbstractHandler