1
0
mirror of https://github.com/aNNiMON/HotaruFX.git synced 2024-09-19 14:14:21 +03:00

Log runtime errors

This commit is contained in:
Victor 2017-09-07 21:40:44 +03:00
parent e88a1d637d
commit 112af1df83
3 changed files with 30 additions and 7 deletions

View File

@ -1,10 +1,9 @@
package com.annimon.hotarufx; package com.annimon.hotarufx;
import com.annimon.hotarufx.exceptions.Exceptions;
import com.annimon.hotarufx.ui.control.ClickableHyperLink; import com.annimon.hotarufx.ui.control.ClickableHyperLink;
import com.annimon.hotarufx.ui.controller.EditorController; import com.annimon.hotarufx.ui.controller.EditorController;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -33,9 +32,7 @@ public class Main extends Application {
controller.setPrimaryStage(primaryStage); controller.setPrimaryStage(primaryStage);
primaryStage.setScene(scene); primaryStage.setScene(scene);
} catch (IOException ex) { } catch (IOException ex) {
val sw = new StringWriter(); val text = new TextArea(Exceptions.stackTraceToString(ex));
ex.printStackTrace(new PrintWriter(sw));
val text = new TextArea(sw.toString());
text.setEditable(false); text.setEditable(false);
primaryStage.setScene(new Scene(text)); primaryStage.setScene(new Scene(text));
} }

View File

@ -0,0 +1,18 @@
package com.annimon.hotarufx.exceptions;
import java.io.PrintWriter;
import java.io.StringWriter;
import lombok.val;
public final class Exceptions {
private Exceptions() {
throw new IllegalStateException("Oh là là!");
}
public static String stackTraceToString(Throwable throwable) {
val sw = new StringWriter();
throwable.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
}

View File

@ -4,6 +4,8 @@ import com.annimon.hotarufx.Main;
import com.annimon.hotarufx.bundles.BundleLoader; import com.annimon.hotarufx.bundles.BundleLoader;
import com.annimon.hotarufx.bundles.CompositionBundle; import com.annimon.hotarufx.bundles.CompositionBundle;
import com.annimon.hotarufx.bundles.NodesBundle; import com.annimon.hotarufx.bundles.NodesBundle;
import com.annimon.hotarufx.exceptions.Exceptions;
import com.annimon.hotarufx.exceptions.HotaruRuntimeException;
import com.annimon.hotarufx.io.DocumentListener; import com.annimon.hotarufx.io.DocumentListener;
import com.annimon.hotarufx.io.DocumentManager; import com.annimon.hotarufx.io.DocumentManager;
import com.annimon.hotarufx.io.FileManager; import com.annimon.hotarufx.io.FileManager;
@ -144,7 +146,13 @@ public class EditorController implements Initializable, DocumentListener {
logPane.setExpanded(true); logPane.setExpanded(true);
return; return;
} }
program.accept(new InterpreterVisitor(), context); try {
program.accept(new InterpreterVisitor(), context);
} catch (RuntimeException e) {
logError(Exceptions.stackTraceToString(e));
logPane.setExpanded(true);
return;
}
val stage = new Stage(); val stage = new Stage();
val composition = context.composition(); val composition = context.composition();
@ -258,7 +266,7 @@ public class EditorController implements Initializable, DocumentListener {
" .add(300 ms, 200)\n" + " .add(300 ms, 200)\n" +
" .add(1 sec, 50)\n" + " .add(1 sec, 50)\n" +
"\n" + "\n" +
"render(A)"); "render(A)\n");
} }
private String readProgram(String path) { private String readProgram(String path) {