fix error handling

This commit is contained in:
Peter Hormanns 2017-12-29 18:07:16 +01:00
parent 43d542d63b
commit ba45fc8886

View File

@ -75,6 +75,12 @@ public class Main {
for (String ll : lines) { for (String ll : lines) {
console.println(ll); console.println(ll);
} }
} catch (RuntimeException re) {
if (re.getCause() instanceof JSCliException) {
console.println(findRootException(re.getCause()));
} else {
throw re;
}
} catch (JSCliException e) { } catch (JSCliException e) {
console.println(findRootException(e)); console.println(findRootException(e));
} }
@ -92,7 +98,7 @@ public class Main {
return "bye".equals(trimmedCommand) || "exit".equals(trimmedCommand) || "quit".equals(trimmedCommand); return "bye".equals(trimmedCommand) || "exit".equals(trimmedCommand) || "quit".equals(trimmedCommand);
} }
private static String findRootException(final Exception exp) { private static String findRootException(final Throwable exp) {
Throwable cause = exp; Throwable cause = exp;
while (cause.getCause() != null && cause.getCause() != cause) { while (cause.getCause() != null && cause.getCause() != cause) {
cause = cause.getCause(); cause = cause.getCause();