Function catchError

  • Catches all iteration errors up the chain (see Error Handling).

    Below is explicit error handling, by injecting catchError into the pipeline:

    import {pipe, catchError, map} from 'iter-ops';

    const i = pipe(
    [1, 2, 3],
    map(a => {
    if (a % 2 === 0) {
    throw new Error('even number');
    }
    return a;
    }),
    catchError((err, ctx) => {
    console.log(err);
    })
    );

    What you can do inside the error handler:

    • nothing (we let it skip the value)
    • provide a new/alternative value (via ctx.emit(value))
    • re-throw the original error
    • throw a new error

    Below is implicit error handling, via catch, which just appends catchError to the pipeline:

    import {pipe, map} from 'iter-ops';

    const i = pipe(
    [1, 2, 3],
    map(a => {
    if (a % 2 === 0) {
    throw new Error('even number');
    }
    return a;
    })
    )
    .catch((err, ctx) => {
    console.log(err);
    });

    Type Parameters

    • T

    Parameters

    Returns Operation<T, T>