1 11 package org.eclipse.core.runtime; 12 13 import org.eclipse.core.internal.runtime.*; 14 import org.eclipse.osgi.util.NLS; 15 16 25 public final class SafeRunner { 26 27 34 public static void run(ISafeRunnable code) { 35 Assert.isNotNull(code); 36 try { 37 code.run(); 38 } catch (Exception e) { 39 handleException(code, e); 40 } catch (LinkageError e) { 41 handleException(code, e); 42 } 43 } 44 45 private static void handleException(ISafeRunnable code, Throwable e) { 46 if (!(e instanceof OperationCanceledException)) { 47 Activator activator = Activator.getDefault(); 49 String pluginId = null; 50 if (activator != null) 51 pluginId = activator.getBundleId(code); 52 if (pluginId == null) 53 pluginId = IRuntimeConstants.PI_COMMON; 54 String message = NLS.bind(CommonMessages.meta_pluginProblems, pluginId); 55 IStatus status; 56 if (e instanceof CoreException) { 57 status = new MultiStatus(pluginId, IRuntimeConstants.PLUGIN_ERROR, message, e); 58 ((MultiStatus) status).merge(((CoreException) e).getStatus()); 59 } else { 60 status = new Status(IStatus.ERROR, pluginId, IRuntimeConstants.PLUGIN_ERROR, message, e); 61 } 62 if (!RuntimeLog.isEmpty()) 64 RuntimeLog.log(status); 65 else 66 e.printStackTrace(); 67 } 68 code.handleException(e); 69 } 70 } 71 | Popular Tags |