Chromium Code Reviews| Index: pkg/kernel/lib/interpreter/interpreter.dart |
| diff --git a/pkg/kernel/lib/interpreter/interpreter.dart b/pkg/kernel/lib/interpreter/interpreter.dart |
| index 710d106bac7bbac513fbc35d0ba67d3c8cb610a9..e85045273c3f3b5bca3a90088d0da94fd2157f56 100644 |
| --- a/pkg/kernel/lib/interpreter/interpreter.dart |
| +++ b/pkg/kernel/lib/interpreter/interpreter.dart |
| @@ -252,6 +252,13 @@ class Evaluator extends ExpressionVisitor1<Configuration, EvalConfiguration> { |
| config.continuation, config.environment.thisInstance); |
| } |
| + Configuration visitThrow(Throw node, EvalConfiguration config) { |
| + var cont = new ThrowEK(config.handlers); |
| + |
| + return new EvalConfiguration( |
| + node.expression, config.environment, config.handlers, cont); |
| + } |
| + |
| // Evaluation of BasicLiterals. |
| Configuration visitStringLiteral( |
| StringLiteral node, EvalConfiguration config) { |
| @@ -1201,6 +1208,16 @@ class InitializerListEK extends ExpressionContinuation { |
| } |
| } |
| +class ThrowEK extends ExpressionContinuation { |
| + final Handlers handlers; |
| + |
| + ThrowEK(this.handlers); |
| + |
| + Configuration call(Value value) { |
| + return new ThrowConfiguration(handlers.handler, value, handlers.stackTrace); |
| + } |
| +} |
| + |
| // ------------------------------------------------------------------------ |
| // Exceptions Handlers |
| // ------------------------------------------------------------------------ |
| @@ -1211,6 +1228,22 @@ abstract class ExceptionHandler extends Continuation { |
| Configuration call(Value exception, StackTrace stacktrace); |
| } |
| +/// Handler for showing an exception to the user and returning a halting the |
| +/// execution of the program when an exception is not handled. |
| +class MainHandler extends ExceptionHandler { |
| + ExceptionHandler get nextHandler => |
| + throw 'The current handler is the main exception handler'; |
| + |
| + Configuration call(Value exception, StackTrace stacktrace) { |
| + var errorMessage = 'Uncaught exception ' |
| + '"${exception.value.runtimeType} : ${exception.value}"\n' |
| + '${stacktrace.toString()}'; |
| + log.info(errorMessage); |
| + print(errorMessage); |
| + return null; |
| + } |
| +} |
| + |
| // ------------------------------------------------------------------------ |
| // Exceptions |
| // ------------------------------------------------------------------------ |
| @@ -1232,10 +1265,9 @@ class Handlers { |
| Handlers(this.handler, this.stackTrace, this.currentStackTrace, |
| this.currentException); |
| - // TODO(zhivkag): Add a top level handler for initial exception state. |
| Handlers.initial() |
| - : handler = null, |
| - stackTrace = null, |
| + : handler = new MainHandler(), |
| + stackTrace = new StackTrace(null, null), |
| currentStackTrace = null, |
| currentException = null; |
| } |
| @@ -1245,6 +1277,16 @@ class StackTrace { |
| final StackTrace stackTrace; |
| StackTrace(this.expression, this.stackTrace); |
| + |
| + String toString() { |
| + var buffer = new StringBuffer('in main()'); |
| + var current = this; |
| + while (current.expression != null) { |
| + buffer.write('at ${current.expression.toString()}'); |
|
Dmitry Stefantsov
2017/08/03 09:01:36
I think we need a newline at the end of this strin
zhivkag
2017/08/03 10:35:50
Done.
|
| + current = current.stackTrace; |
| + } |
| + return buffer.toString(); |
| + } |
| } |
| /// Executes statements. |