1 package org.argosfields.util;
2
3 import java.io.PrintWriter;
4 import java.io.StringWriter;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.argosfields.resource.ResourceManager;
9 import org.eclipse.core.runtime.MultiStatus;
10 import org.eclipse.core.runtime.Status;
11 import org.eclipse.jface.dialogs.ErrorDialog;
12 import org.eclipse.jface.window.Window;
13 import org.eclipse.swt.widgets.Display;
14 import org.eclipse.swt.widgets.Shell;
15
16 /***
17 * ExceptionHandler.java
18 * @author Xavier Cho
19 * @version $Revision: 1.2 $ $Date: 2004/04/15 05:42:45 $
20 */
21 public class ExceptionHandler implements Window.IExceptionHandler {
22 private static Log log = LogFactory.getLog(ExceptionHandler.class);
23
24 public void handleException(final Throwable t) {
25 handleException(null, t);
26 }
27
28 public static void handleException(final String msg, final Throwable t) {
29 ResourceManager resources = ResourceManager.getInstance();
30 String message = msg;
31
32 try {
33 if (message == null) {
34 message = resources.getString("error.unknown");
35 }
36 } catch (Throwable th) {
37 message = "Unhandled exception has occurred.";
38 }
39
40 try {
41 StringWriter writer = new StringWriter();
42 PrintWriter printer = new PrintWriter(writer);
43
44 t.printStackTrace(printer);
45
46 Status status =
47 new Status(
48 Status.ERROR,
49 ExceptionHandler.class.getName(),
50 Status.OK,
51 writer.toString(),
52 t);
53
54 final MultiStatus multiStatus =
55 new MultiStatus(
56 ExceptionHandler.class.getName(),
57 Status.OK,
58 message,
59 t);
60 multiStatus.add(status);
61
62 final Display display = Display.getDefault();
63 if (display != null) {
64 final String title = resources.getString("dialog.title.error");
65
66 Runnable runner = new Runnable() {
67 public void run() {
68 Shell parent = null;
69
70 if (display != null) {
71 parent = display.getActiveShell();
72 }
73
74 ErrorDialog.openError(parent, title, null, multiStatus);
75 }
76 };
77
78 display.syncExec(runner);
79 }
80 } catch (Throwable th) {
81 log.warn("Unable to open error dialog : " + th.getMessage(), th);
82 }
83
84 if (log.isErrorEnabled()) {
85 log.error(msg, t);
86 }
87 }
88 }
This page was automatically generated by Maven