From 2cca85baec1c4979b4cf3beb80cbab9d8dd89754 Mon Sep 17 00:00:00 2001 From: Bartosz Firyn Date: Fri, 11 Jan 2013 15:45:53 +0100 Subject: [PATCH] Ignore exception when removing ShutdownHook on shutdown --- .../src/main/java/com/github/sarxos/webcam/Webcam.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java index 72abec5c..f8a64dc0 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java @@ -587,7 +587,11 @@ protected void dispose() { // hook can be null because there is a possibility that webcam has never // been open and therefore hook was not created if (hook != null) { - Runtime.getRuntime().removeShutdownHook(hook); + try { + Runtime.getRuntime().removeShutdownHook(hook); + } catch (IllegalStateException e) { + // ignore, it means that shutdown is in progress + } } open = false;