throwUncheckedIfOrNull method

T throwUncheckedIfOrNull(
  1. bool condition(
    1. T value
    ), {
  2. required String prefix,
  3. ({String english, String locale}) message = (english: '', locale: ''),
  4. StackTrace? stackTrace,
})

데이터가 null이거나 특정 조건(condition)을 만족할 경우 UncheckedError를 발생시킵니다.

데이터가 존재하지 않거나, 시스템 불변성(Invariant)이 깨진 치명적 상태일 때 사용합니다. throwUncheckedIfNull을 통해 원천적인 Null 체크를 마친 후 상세 로직 위반 여부를 확인합니다.

Throws an UncheckedError if the value is null or satisfies the specified condition. Checks for nullity first, then confirms if system invariants are maintained.

Implementation

T throwUncheckedIfOrNull(
  bool Function(T value) condition, {
  required String prefix,
  ({String english, String locale}) message = (english: '', locale: ''),
  StackTrace? stackTrace,
}) {
  final T value = throwUncheckedIfNull(prefix: prefix, message: message, stackTrace: stackTrace);

  if (condition(value)) {
    throw GenericUncheckedError(
      value: value,
      prefix: prefix,
      message: message,
      stackTrace: stackTrace ?? StackTrace.current,
    );
  }
  return value;
}