Skip to content

Commit

Permalink
Handles (silences) harmless exceptions in the main app loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Aug 20, 2021
1 parent 5483686 commit 09bd85c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
21 changes: 9 additions & 12 deletions msi.gama.application/src/msi/gama/application/Application.java
Expand Up @@ -22,7 +22,6 @@
import static org.eclipse.jface.dialogs.MessageDialog.openError;
import static org.eclipse.jface.dialogs.MessageDialog.openQuestion;
import static org.eclipse.ui.PlatformUI.RETURN_RESTART;
import static org.eclipse.ui.PlatformUI.createAndRunWorkbench;
import static org.eclipse.ui.PlatformUI.getWorkbench;
import static org.eclipse.ui.PlatformUI.isWorkbenchRunning;
import static org.eclipse.ui.internal.util.PrefUtil.getInternalPreferenceStore;
Expand All @@ -41,6 +40,7 @@
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.Workbench;
import org.eclipse.ui.internal.ide.application.DelayedEventsProcessor;

import msi.gama.application.workbench.ApplicationWorkbenchAdvisor;
Expand Down Expand Up @@ -124,21 +124,18 @@ public Object start(final IApplicationContext context) throws Exception {
createProcessor();
final Object check = checkWorkspace();
if (EXIT_OK.equals(check)) return EXIT_OK;
// if ( check == EXIT_RESTART ) {
// ClearWorkspace(true);
// No need to restart : the value will be checked later
// return EXIT_RESTART;
// }
Display display = null;
try {
display = PlatformUI.createDisplay();
checkWorkbenchXMI();
// final String splash = getProperty("org.eclipse.equinox.launcher.splash.location");
// if ( splash != null ) {
// setProperty("org.eclipse.equinox.launcher.splash.location", splash.replace("bmp", "png"));
// }
final int returnCode = createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
if (returnCode == RETURN_RESTART) return EXIT_RESTART;

try {
final int returnCode = Workbench.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
if (returnCode == RETURN_RESTART) return EXIT_RESTART;
} catch (Throwable t) {
DEBUG.OUT("Error in application: " + t.getMessage());
}

return EXIT_OK;
} finally {
if (display != null) { display.dispose(); }
Expand Down
Expand Up @@ -188,7 +188,6 @@ public String getInitialWindowPerspectiveId() {
@Override
public boolean preShutdown() {
try {
// saveEclipsePreferences();
GAMA.closeAllExperiments(true, true);
PerspectiveHelper.deleteCurrentSimulationPerspective();
// So that they are not saved to the workbench.xmi file
Expand Down Expand Up @@ -220,16 +219,6 @@ public void preStartup() {
if (checkCopyOfBuiltInModels()) { WorkspaceModelsManager.linkSampleModelsToWorkspace(); }

}
//
// private void saveEclipsePreferences() {
// final IPreferencesService service = Platform.getPreferencesService();
//
// try (final FileOutputStream outputStream =
// new FileOutputStream(Platform.getInstanceLocation().getURL().getPath() + "/.gama.epf")) {
// service.exportPreferences(service.getRootNode(), WorkspacePreferences.getPreferenceFilters(), outputStream);
// } catch (final CoreException | IOException e1) {}
//
// }

/**
* Method getWorkbenchErrorHandler()
Expand All @@ -251,11 +240,16 @@ public void handle(final StatusAdapter statusAdapter, final int style) {
final String message = statusAdapter.getStatus().getMessage();
// Stupid Eclipse
if (!message.contains("File toolbar contribution item") && !message.contains("Duplicate template id")) {
DEBUG.OUT("GAMA Caught a workbench message : " + message);
DEBUG.OUT("GAMA caught a workbench message : " + message);
}
if (e != null) { e.printStackTrace(); }
if (e != null) { DEBUG.OUT("GAMA caught an error in the main application loop: " + e.getMessage()); }
}
};
}

@Override
public void eventLoopException(final Throwable t) {
DEBUG.OUT("GAMA caught an error in the main application loop: " + t.getMessage());
}

}

0 comments on commit 09bd85c

Please sign in to comment.