Beispiel #1
0
  private void handleException(ParserExceptionWithSource exception) {
    ParserException e = exception.getCause();
    String sourceCode = exception.getSourceCode();
    int lineOffset = exception.getSource().getLine();

    String sourceInfo = String.format("%s:%d:%d", e.getFile(), e.getLine(), e.getColumn());
    int start = skipLines(sourceCode, e.getLine() - lineOffset);
    int end = nextLineTerminator(sourceCode, start);
    String offendingLine = sourceCode.substring(start, end);
    String marker = Strings.repeat('.', Math.max(e.getColumn() - 1, 0)) + '^';

    console.printf("%s %s: %s%n", sourceInfo, e.getType(), e.getFormattedMessage());
    console.printf("%s %s%n", sourceInfo, offendingLine);
    console.printf("%s %s%n", sourceInfo, marker);
    printStackTrace(e);
  }
Beispiel #2
0
 /**
  * REPL: Print
  *
  * @param realm the realm instance
  * @param result the object to be printed
  */
 private void print(Realm realm, Object result) {
   if (result != UNDEFINED) {
     console.printf("%s%n", sourceBuilder.toSource(realm.defaultContext(), result));
   }
 }
Beispiel #3
0
 private void handleException(Realm realm, ScriptException e) {
   String message = formatMessage("uncaught_exception", e.getMessage(realm.defaultContext()));
   console.printf("%s%n", message);
   printScriptStackTrace(realm, e);
   printStackTrace(e);
 }
Beispiel #4
0
 private void handleException(Realm realm, UnhandledRejectionException e) {
   String message = formatMessage("unhandled_rejection", e.getMessage(realm.defaultContext()));
   console.printf("%s%n", message);
   printStackTrace(e.getCauseIfPresent());
 }
Beispiel #5
0
 private void handleException(IOException e) {
   String message = Objects.toString(e.getMessage(), "");
   console.printf("%s: %s%n", e.getClass().getSimpleName(), message);
   printStackTrace(e);
 }