-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathLastResortHandler.java
More file actions
43 lines (35 loc) · 1.39 KB
/
LastResortHandler.java
File metadata and controls
43 lines (35 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package nodebox.client;
import javax.swing.*;
import java.util.Locale;
public class LastResortHandler implements Thread.UncaughtExceptionHandler {
public static void handle(Throwable t) {
System.out.println("handle!");
showException(Thread.currentThread(), t);
}
public void uncaughtException(final Thread t, final Throwable e) {
if (SwingUtilities.isEventDispatchThread()) {
showException(t, e);
} else {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
showException(t, e);
}
});
}
}
private static void showException(Thread t, Throwable e) {
String msg = String.format(Locale.US, "Unexpected problem on thread %s: %s",
t.getName(), e.getMessage());
logException(t, e);
// note: in a real app, you should locate the currently focused frame
// or dialog and use it as the parent. In this example, I'm just passing
// a null owner, which means this dialog may get buried behind
// some other screen.
ExceptionDialog ed = new ExceptionDialog(null, e);
ed.setVisible(true);
}
private static void logException(Thread t, Throwable e) {
// todo: start a thread that sends an email, or write to a log file, or
// send a JMS message...whatever
}
}