Skip to content

Commit

Permalink
Added exception control and message
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoCau committed Oct 18, 2021
1 parent 57ab1a5 commit beeb795
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/gui/OutputController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import static javafx.scene.paint.Color.RED;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
import java.util.ResourceBundle;

Expand Down Expand Up @@ -81,17 +83,26 @@ public void initialize(URL location, ResourceBundle resources) {
result.setVisible(false);
input.textProperty().addListener(
(observable, oldValue, newValue)-> {
if (lrParser.accept(input.getText())) {
result.setText("Accepted");
result.setTextFill(GREEN);
result.setVisible(true);
try {
if (lrParser.accept(input.getText())) {
result.setText("Accepted");
result.setTextFill(GREEN);
result.setVisible(true);
}
else {
result.setText("Rejected");
result.setTextFill(RED);
result.setVisible(true);
}
output.setText("\n" + lrParser.getLog());
}
else {
result.setText("Rejected");
result.setTextFill(RED);
result.setVisible(true);
catch (Throwable t) {
//output.setText("\n" + lrParser.getLog() + "\n" + t);
var sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
output.setText("\n" + lrParser.getLog() + "\n" + sw.toString());
throw t;
}
output.setText("\n" + lrParser.getLog());
}
);
output.setText("\n" + lrParser.getGrammar());
Expand Down

0 comments on commit beeb795

Please sign in to comment.