1 package net.sourceforge.phpdt.internal.ui.util;
3 import java.io.StringWriter;
4 import java.lang.reflect.InvocationTargetException;
6 import net.sourceforge.phpdt.internal.ui.PHPUIMessages;
7 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
8 import net.sourceforge.phpeclipse.ui.WebUI;
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.core.runtime.IStatus;
12 import org.eclipse.core.runtime.Status;
13 import org.eclipse.jface.dialogs.ErrorDialog;
14 import org.eclipse.jface.dialogs.MessageDialog;
15 import org.eclipse.swt.widgets.Shell;
17 public class ExceptionHandler {
18 private static ExceptionHandler fgInstance = new ExceptionHandler();
20 public static void log(Throwable t, String message) {
21 WebUI.getDefault().getLog().log(
22 new Status(IStatus.ERROR, WebUI.PLUGIN_ID,
23 IStatus.ERROR, message, t));
26 // public static void handle(CoreException e, String title, String message) {
27 // handle(e, WebUI.getActiveWorkbenchShell(), title, message);
30 public static void handle(CoreException e, Shell parent, String title,
32 fgInstance.perform(e, parent, title, message);
35 // public static void handle(InvocationTargetException e, String title,
37 // handle(e, WebUI.getActiveWorkbenchShell(), title, message);
40 public static void handle(InvocationTargetException e, Shell parent,
41 String title, String message) {
42 fgInstance.perform(e, parent, title, message);
45 protected void perform(CoreException e, Shell shell, String title,
48 IStatus status = e.getStatus();
50 ErrorDialog.openError(shell, title, message, status);
52 displayMessageDialog(e, e.getMessage(), shell, title, message);
56 protected void perform(InvocationTargetException e, Shell shell,
57 String title, String message) {
58 Throwable target = e.getTargetException();
59 if (target instanceof CoreException) {
60 perform((CoreException) target, shell, title, message);
63 if (e.getMessage() != null && e.getMessage().length() > 0) {
64 displayMessageDialog(e, e.getMessage(), shell, title, message);
66 displayMessageDialog(e, target.getMessage(), shell, title,
72 private void displayMessageDialog(Throwable t, String exceptionMessage,
73 Shell shell, String title, String message) {
74 StringWriter msg = new StringWriter();
75 if (message != null) {
79 if (exceptionMessage == null || exceptionMessage.length() == 0)
80 msg.write(PHPUIMessages
81 .getString("ExceptionDialog.seeErrorLogMessage"));
83 msg.write(exceptionMessage);
84 MessageDialog.openError(shell, title, msg.toString());