From: Fredrik Tolf Date: Wed, 16 Feb 2022 18:25:11 +0000 (+0100) Subject: Log errors when closing watchers. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=7a3bde5c801b293fae82e4e24b740164d9659c74;p=jagi.git Log errors when closing watchers. --- diff --git a/src/jagi/event/Driver.java b/src/jagi/event/Driver.java index a8475b4..4d23c76 100644 --- a/src/jagi/event/Driver.java +++ b/src/jagi/event/Driver.java @@ -26,7 +26,18 @@ public class Driver { current.set(this); w.handle(evs); } catch(Throwable t) { - error(w, t); + error(w, t, "handling event"); + } finally { + current.remove(); + } + } + + protected void close(Watcher w) { + try { + current.set(this); + w.close(); + } catch(Throwable t) { + error(w, t, "closing"); } finally { current.remove(); } @@ -36,8 +47,8 @@ public class Driver { worker.submit(task); } - protected void error(Watcher w, Throwable t) { - hlog.log(Level.WARNING, w + ": uncaught error when handling event", t); + protected void error(Watcher w, Throwable t, String thing) { + hlog.log(Level.WARNING, w + ": uncaught error when " + thing, t); remove(w); } @@ -164,7 +175,7 @@ public class Driver { double timeout = w.timeout(); boolean hastime = timeout < Double.POSITIVE_INFINITY; if(evs < 0) { - submit(w::close); + submit(() -> close(w)); return; } w.added(Driver.this); @@ -188,7 +199,7 @@ public class Driver { throw(new RuntimeException(w + ": inconsistent internal state")); if(wc == null) throw(new IllegalStateException(w + ": not registered")); - submit(w::close); + submit(() -> close(w)); poll.wakeup(); }