1 11 package org.eclipse.jdt.internal.debug.ui; 12 13 14 import java.io.StringWriter ; 15 import java.lang.reflect.InvocationTargetException ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.jface.dialogs.ErrorDialog; 20 import org.eclipse.jface.dialogs.MessageDialog; 21 import org.eclipse.swt.widgets.Shell; 22 23 30 public class ExceptionHandler { 31 32 private static ExceptionHandler fgInstance= new ExceptionHandler(); 33 34 42 public static void handle(CoreException e, String title, String message) { 43 handle(e, JDIDebugUIPlugin.getActiveWorkbenchShell(), title, message); 44 } 45 46 54 public static void handle(CoreException e, Shell parent, String title, String message) { 55 fgInstance.perform(e, parent, title, message); 56 } 57 58 66 public static void handle(InvocationTargetException e, String title, String message) { 67 handle(e, JDIDebugUIPlugin.getActiveWorkbenchShell(), title, message); 68 } 69 70 78 public static void handle(InvocationTargetException e, Shell parent, String title, String message) { 79 fgInstance.perform(e, parent, title, message); 80 } 81 82 84 protected void perform(CoreException e, Shell shell, String title, String message) { 85 IStatus status= e.getStatus(); 86 JDIDebugUIPlugin.log(e); 87 if (status != null) { 88 ErrorDialog.openError(shell, title, message, status); 89 } else { 90 displayMessageDialog(e.getMessage(), shell, title, message); 91 } 92 } 93 94 protected void perform(InvocationTargetException e, Shell shell, String title, String message) { 95 Throwable target= e.getTargetException(); 96 if (target instanceof CoreException) { 97 perform((CoreException)target, shell, title, message); 98 } else { 99 JDIDebugUIPlugin.log(e); 100 if (e.getMessage() != null && e.getMessage().length() > 0) { 101 displayMessageDialog(e.getMessage(), shell, title, message); 102 } else { 103 displayMessageDialog(target.getMessage(), shell, title, message); 104 } 105 } 106 } 107 108 private void displayMessageDialog(String exceptionMessage, Shell shell, String title, String message) { 109 StringWriter msg= new StringWriter (); 110 if (message != null) { 111 msg.write(message); 112 msg.write("\n\n"); } 114 if (exceptionMessage == null || exceptionMessage.length() == 0) { 115 msg.write(DebugUIMessages.ExceptionHandler_seeErrorLogMessage); 116 } 117 else { 118 msg.write(exceptionMessage); 119 } 120 MessageDialog.openError(shell, title, msg.toString()); 121 } 122 } 123 | Popular Tags |