Catches all iteration errors up the chain (see Error Handling).
Below is explicit error handling, by injecting catchError into the pipeline:
catchError
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); })); Copy
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:
ctx.emit(value)
Below is implicit error handling, via catch, which just appends catchError to the pipeline:
catch
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); }); Copy
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); });
Catches all iteration errors up the chain (see Error Handling).
Below is explicit error handling, by injecting
catchError
into the pipeline:What you can do inside the error handler:
ctx.emit(value)
)Below is implicit error handling, via
catch
, which just appendscatchError
to the pipeline: