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);

  // 2. Create and throw an InternalInterpreterException.
  final message = stringify(thrownValue); // Keep for debug log
  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.
}