catching method

ValidatorT<S, T> catching([
  1. Selector<Exception, ValidationError>? handler
])

Creates a new validator from the caller that will catch an errors when evaluating the validating function.

Implementation

ValidatorT<S, T> catching([Selector<Exception, ValidationError>? handler]) {
  return (S input) {
    try {
      return this(input);
    } catch (e, _) {
      return Left([handler?.call(e as Exception) ?? e]);
    }
  };
}