public class MessagingUtils {
public final static String UNEXPECTED_ERROR_MESSAGE = "This is an unexpected error.";
public final static String CONTACT_MESSAGE = System.getProperty("line.separator") + "Please contact EDIT Support (EditSupport@bgbm.org) with the error trace below (click on the 'Details' button).";
+ public final static String DEFAULT_MESSAGE = "Error thrown but no associated message";
/**
* Gets the Log4J logger for a given class
public static String getStackTraceAndContextInfo(Throwable t, List<String> contextInfo) {
StringBuffer stackTraceAndContextInfo = new StringBuffer();
+ Throwable throwable = t;
for(String infoItem : contextInfo) {
stackTraceAndContextInfo.append(infoItem + System.getProperty("line.separator"));
}
StringWriter sw = new StringWriter();
- t.printStackTrace(new PrintWriter(sw));
+
+ if(throwable == null) {
+ throwable = getDefaultThrowable();
+ }
+ throwable.printStackTrace(new PrintWriter(sw));
stackTraceAndContextInfo.append(sw.toString());
return stackTraceAndContextInfo.toString();
}
+ private static Throwable getDefaultThrowable() {
+ return new Throwable("Error thrown but no associated exception");
+ }
+
+
+
/**
* Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
*
final Throwable t,
boolean addContactMesg) {
-
+ Throwable throwable = t;
StringBuffer sbStackTrace = new StringBuffer();
// We need to build a MultiStatus object since the simple
childStatuses.add(new Status(IStatus.ERROR, pluginId, infoItem));
}
+ if(throwable == null) {
+ throwable = getDefaultThrowable();
+ }
+
// add main execption
- for (StackTraceElement ste : t.getStackTrace()) {
+ for (StackTraceElement ste : throwable.getStackTrace()) {
childStatuses.add(new Status(IStatus.ERROR, pluginId, "at " + ste.toString()));
}
// add cause
- if(t.getCause() != null) {
+ if(throwable.getCause() != null) {
childStatuses.add(new Status(IStatus.ERROR, pluginId, ""));
- childStatuses.add(new Status(IStatus.ERROR, pluginId, "Caused by : " + t.getCause().toString()));
- for (StackTraceElement ste : t.getCause().getStackTrace()) {
+ childStatuses.add(new Status(IStatus.ERROR, pluginId, "Caused by : " + throwable.getCause().toString()));
+ for (StackTraceElement ste : throwable.getCause().getStackTrace()) {
// build & add status
childStatuses.add(new Status(IStatus.ERROR, pluginId, "at " + ste.toString()));
}
String finalMessage = message;
if(finalMessage == null || finalMessage.isEmpty()) {
- finalMessage = "";
+ finalMessage = DEFAULT_MESSAGE;
}
if(addContactMesg) {
MultiStatus ms = new MultiStatus(pluginId,
IStatus.ERROR,
childStatuses.toArray(new Status[] {}),
- t.toString(),
- t);
+ throwable.toString(),
+ throwable);
- errorDialog(title, source, t, contextInfo, finalMessage, ms);
- }
-
- /**
- * Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
- *
- * @param title
- * a {@link java.lang.String} object.
- * @param source
- * a {@link java.lang.Object} object.
- * @param status
- * a {@link org.eclipse.core.runtime.IStatus} object.
- */
- private static void errorDialog(final String title,
- final Object source,
- final String message,
- final IStatus status) {
-
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, status);
- ced.open();
- Class<? extends Object> clazz = source != null ? source.getClass() : this.getClass();
- error(clazz, status);
- }
- });
+ errorDialog(title, source, throwable, contextInfo, finalMessage, ms);
}
/**