visitTry method

  1. @override
dynamic visitTry(
  1. TryStatement node
)

Implementation

@override
visitTry(TryStatement node) {
  if (node.handler == null && node.finalizer == null) {
    throw JSException(node.line ?? 0,
        "Syntax Error: a try block must have a corresponding catch or finally");
  }
  try {
    node.block.visitBy(this);
  } on ControlFlowReturnException {
    rethrow; // Re-throw control flow exceptions
  } on ControlFlowBreakException {
    rethrow;
  } on ControlFlowContinueException {
    rethrow;
  } catch (e) {
    if (node.handler != null) {
      dynamic exceptionValue = getExceptionValue(e);
      Map<String, dynamic> ctxMap = {};
      if (node.handler!.param != null) {
        ctxMap[node.handler!.param.value] = JSCustomException(exceptionValue);
      }
      Context context = SimpleContext(ctxMap);
      // Clone the interpreter with this new context
      JSInterpreter interpreter =
          cloneForContext(node.handler!, context, true);
      interpreter.visitCatchClause(node.handler!);
    }
  } finally {
    if (node.finalizer != null) {
      node.finalizer!.visitBy(this);
    }
  }
}