Commit c76ce055 authored by Quentin DRUAULT-AUBIN's avatar Quentin DRUAULT-AUBIN
Browse files

[Error] Add another catch for other exceptions

parent 5b0b730b
......@@ -17,6 +17,8 @@ import com.utclo23.data.structure.ShipType;
import com.utclo23.ihmtable.structure.CoordinatesGenerator;
import com.utclo23.ihmtable.structure.InGameStats;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
......@@ -40,6 +42,7 @@ import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
......@@ -730,6 +733,45 @@ public class InGameGUIController {
// Display it.
alert.showAndWait();
}
/**
* Display a popup when there is an unknown error.
* @param ex : the exception that occured
*/
private void displayErrorPopup(Exception ex) {
// Create the popup.
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("An error occurred");
alert.setContentText(ex.getMessage());
// Create expandable Exception.
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
String exceptionText = sw.toString();
Label label = new Label("The exception stacktrace was:");
TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setMaxWidth(Double.MAX_VALUE);
textArea.setMaxHeight(Double.MAX_VALUE);
GridPane.setVgrow(textArea, Priority.ALWAYS);
GridPane.setHgrow(textArea, Priority.ALWAYS);
GridPane expContent = new GridPane();
expContent.setMaxWidth(Double.MAX_VALUE);
expContent.add(label, 0, 0);
expContent.add(textArea, 0, 1);
// Set expandable Exception into the dialog pane.
alert.getDialogPane().setExpandableContent(expContent);
alert.showAndWait();
}
private class AttackEvent implements EventHandler {
......@@ -1113,6 +1155,12 @@ public class InGameGUIController {
// Wrong coordinates -> reset.
ship.getListCoord().clear();
} catch (Exception e) {
Logger.getLogger(InGameGUIController.class.getName()).log(Level.SEVERE, null, e);
// Display the error.
displayErrorPopup(e);
// Wrong coordinates -> reset.
ship.getListCoord().clear();
} finally {
// The ship was found, no need to continue the loop.
break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment