Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Commit

Permalink
Added improved error Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
aersamkull committed Jun 9, 2015
1 parent afd3260 commit ae9b252
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.awt.event.WindowEvent;

import ch.fhnw.cantoneditor.datautils.DataStorage;
import ch.fhnw.cantoneditor.datautils.TranslationManager;
import ch.fhnw.cantoneditor.views.ErrorWindow;
import ch.fhnw.cantoneditor.views.Overview;

/** The main controller for Displaying the whole view with editing and tables */
Expand Down Expand Up @@ -44,9 +46,13 @@ public void windowClosed(WindowEvent arg0) {
System.exit(0);// Close the application reporting success
}
});

} catch (Exception err) {// Should never occur, and if we are dead anyway :)
err.printStackTrace();
throw new RuntimeException("Fatal error when starting application", err);

ErrorWindow window = new ErrorWindow(TranslationManager.getInstance().translate("FatalErrorWhenStarting",
"A fatal error occured when starting the application"), err);
window.show();
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/ch/fhnw/cantoneditor/views/ErrorWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ch.fhnw.cantoneditor.views;

import java.awt.Dimension;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

import ch.fhnw.cantoneditor.datautils.TranslationManager;
import ch.fhnw.observation.ValueSubscribable;

/** For displaying a fatal error */
public class ErrorWindow {
private final ValueSubscribable<String> title;
private final Exception exception;

public ErrorWindow(ValueSubscribable<String> title, Exception exception) {
this.title = title;
this.exception = exception;
}

public void show() {
JFrame frame = new JFrame();
TranslationManager.getInstance().translate("ErrorOccured", "An Error occured").bindTo(frame::setTitle);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.PAGE_AXIS));
JLabel desc = new JLabel();
this.title.bindTo((s) -> desc.setText(s + ": "));
frame.getContentPane().add(desc);
frame.getContentPane().add(Box.createVerticalStrut(20));
frame.getContentPane().add(new JLabel(this.exception.toString()));
frame.setMinimumSize(new Dimension(350, 200));
frame.pack();
frame.setVisible(true);
}
}
4 changes: 3 additions & 1 deletion src/main/resources/ApplicationTranslation.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ AddItem=Add "{item}" to "{list}"
RemoveItem=Remove "{item}" from "{list}"
PropertyChangeObservable=Change "{old}" to "{new}"
Inhabitants=Inhabitants
Area=Area
Area=Area
FatalErrorWhenStarting=A fatal error occured when starting the application
ErrorOccured=An Error occured
4 changes: 3 additions & 1 deletion src/main/resources/ApplicationTranslation_de_CH.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ Search=Suechi
AddItem="{item}" zu "{list}" hinzuefüege
RemoveItem="{item}" vo de "{list}" lösche
Inhabitants=Iwohner
Area=Flächi
Area=Flächi
FatalErrorWhenStarting=E gatastrophale Fähler isch bim Starte vom Progrämmli passiert
ErrorOccured=Ä Fähler ist passiert
4 changes: 3 additions & 1 deletion src/main/resources/ApplicationTranslation_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ Search=Suche
AddItem="{item}" zu "{list}" hinzuefüegen
RemoveItem="{item}" von "{list}" löschen
Inhabitants=Einwohner
Area=Fläche
Area=Fläche
FatalErrorWhenStarting=Ein fataler Fehler ist beim Starten der Applikation aufgetreten
ErrorOccured=Ein Fehler ist aufgetreten

0 comments on commit ae9b252

Please sign in to comment.