visitThrowExpression method

  1. @override
Object? visitThrowExpression(
  1. SThrowExpression node
)
override

Visit a SThrowExpression.

Implementation

@override
Object? visitThrowExpression(SThrowExpression node) {
  // 1. Evaluate the expression that is thrown
  final thrownValue = node.expression!.accept<Object?>(this);
  // ghissues62: an awaited operand suspends; hand the suspension up so
  // the state machine resumes this node instead of using the request
  // as a value.
  // `throw await f()` threw the request itself, which never completed.
  if (thrownValue is AsyncSuspensionRequest) return thrownValue;

  // 2. Create and throw an InternalInterpreterException.
  final message = stringify(thrownValue); // Keep for debug log
  if (Logger.isDebug) {
    Logger.debug("[SThrowExpression] Throwing (original value): $message");
  }
  // SCF39: an interpreted `Error` subclass gets its `stackTrace` on the
  // first throw, as Dart sets it.
  if (thrownValue is InterpretedInstance) {
    thrownValue.recordThrowIfError(StackTrace.current);
  }
  // Throw the specific internal exception, wrapping the original value
  throw InternalInterpreterD4rtException(thrownValue);
  // We don't capture stack trace here, the 'catch' block does it.
}