From ba45fc8886110a7ccd68f8bbcfc50c7344367708 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Fri, 29 Dec 2017 18:07:16 +0100 Subject: [PATCH] fix error handling --- cli/src/main/java/de/hsadmin/jscli/Main.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/de/hsadmin/jscli/Main.java b/cli/src/main/java/de/hsadmin/jscli/Main.java index c912293..081a2c4 100644 --- a/cli/src/main/java/de/hsadmin/jscli/Main.java +++ b/cli/src/main/java/de/hsadmin/jscli/Main.java @@ -75,6 +75,12 @@ public class Main { for (String ll : lines) { console.println(ll); } + } catch (RuntimeException re) { + if (re.getCause() instanceof JSCliException) { + console.println(findRootException(re.getCause())); + } else { + throw re; + } } catch (JSCliException e) { console.println(findRootException(e)); } @@ -92,7 +98,7 @@ public class Main { 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; while (cause.getCause() != null && cause.getCause() != cause) { cause = cause.getCause();