use of org.jline.builtins.Options in project karaf by apache.
the class Procedural method doThrow.
protected Object doThrow(CommandSession session, Process process, Object[] argv) throws ThrownException, HelpException, OptionException {
String[] usage = { "throw - throw an exception", "Usage: throw [ message [ cause ] ]", " throw exception", " throw", " -? --help Show help" };
Options opt = parseOptions(session, usage, argv);
if (opt.argObjects().size() == 0) {
Object exception = session.get("exception");
if (exception instanceof Throwable)
throw new ThrownException((Throwable) exception);
else
throw new ThrownException(new Exception());
} else if (opt.argObjects().size() == 1 && opt.argObjects().get(0) instanceof Throwable) {
throw new ThrownException((Throwable) opt.argObjects().get(0));
} else {
String message = opt.argObjects().get(0).toString();
Throwable cause = null;
if (opt.argObjects().size() > 1) {
if (opt.argObjects().get(1) instanceof Throwable) {
cause = (Throwable) opt.argObjects().get(1);
}
}
throw new ThrownException(new Exception(message).initCause(cause));
}
}
Aggregations