Browse Source

more error handling options

tags/2.0.1
Jonathan Cobb 5 years ago
parent
commit
dd5a6b24fc
2 changed files with 11 additions and 1 deletions
  1. +3
    -1
      src/main/java/org/cobbzilla/util/daemon/ZillaRuntime.java
  2. +8
    -0
      src/main/java/org/cobbzilla/util/main/BaseMain.java

+ 3
- 1
src/main/java/org/cobbzilla/util/daemon/ZillaRuntime.java View File

@@ -68,7 +68,9 @@ public class ZillaRuntime {


public interface ExceptionRunnable { void handle(Exception e); } public interface ExceptionRunnable { void handle(Exception e); }


public static final ExceptionRunnable DEFAULT_EX_RUNNABLE = e -> log.error("Error: " + e);
public static final ExceptionRunnable DEFAULT_EX_RUNNABLE = e -> {
log.error("Error: " + e);
};


public static ExceptionRunnable exceptionRunnable (Class<? extends Throwable>[] fatalExceptionClasses) { public static ExceptionRunnable exceptionRunnable (Class<? extends Throwable>[] fatalExceptionClasses) {
return e -> { return e -> {


+ 8
- 0
src/main/java/org/cobbzilla/util/main/BaseMain.java View File

@@ -24,8 +24,16 @@ public abstract class BaseMain<OPT extends BaseMainOptions> {


public void runOrDie () { try { run(); } catch (Exception e) { die("runOrDie: "+e, e); } } public void runOrDie () { try { run(); } catch (Exception e) { die("runOrDie: "+e, e); } }


public void runOrDie (ZillaRuntime.ExceptionRunnable errorHandler) {
try { run(); } catch (Exception e) { errorHandler.handle(e); }
}

public Thread runInBackground () { return background(this::runOrDie); } public Thread runInBackground () { return background(this::runOrDie); }


public Thread runInBackground (ZillaRuntime.ExceptionRunnable errorHandler) {
return background(() -> runOrDie(errorHandler));
}

@Getter private String[] args; @Getter private String[] args;
public void setArgs(String[] args) throws CmdLineException { public void setArgs(String[] args) throws CmdLineException {
this.args = args; this.args = args;


Loading…
Cancel
Save