Modify uncaught exception handler to call System.exit(1).
[controller.git] / opendaylight / logging / bridge / src / main / java / org / opendaylight / controller / logging / bridge / internal / UncaughtExceptionPolicy.java
diff --git a/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/UncaughtExceptionPolicy.java b/opendaylight/logging/bridge/src/main/java/org/opendaylight/controller/logging/bridge/internal/UncaughtExceptionPolicy.java
new file mode 100644 (file)
index 0000000..0545578
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.logging.bridge.internal;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+enum UncaughtExceptionPolicy implements Thread.UncaughtExceptionHandler {
+    ABORT {
+        public static final int EXIT_CODE = 1;
+
+        @Override
+        public void uncaughtException(final Thread t, final Throwable e) {
+            log.error("Thread {} died because of an uncaught exception, forcing virtual machine shutdown", t, e);
+            System.exit(EXIT_CODE);
+        }
+    },
+    IGNORE {
+        @Override
+        public void uncaughtException(final Thread t, final Throwable e) {
+            log.error("Thread {} died because of an uncaught exception", t, e);
+        }
+    };
+
+    private static final Logger log = LoggerFactory.getLogger(UncaughtExceptionPolicy.class);
+}