NoSuchElementException constructor

NoSuchElementException([
  1. String? message
])

Thrown when an operation attempts to access an element that does not exist.

This is commonly used in iteration or stream operations, similar to Java's NoSuchElementException.


❗ Example:

final list = <int>[];
if (list.isEmpty) {
  throw NoSuchElementException('List is empty');
}

Implementation

NoSuchElementException([String? message]) : super(message ?? 'No element found');