try-catch-fn
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

try-catch-fn

Functional try-catch implementation.

More info here: This is how functional try-catch transforms your JavaScript code.

Usage

import { tryCatch } from 'try-catch-fn';

const status = tryCatch({
  tryFn: () => {
    throw new Error('network error');
  },
  catchFn: (err) => 'error',
});

console.log(status); // error

Pass single function argument to simply "silence" any exception it throws.

import { tryCatch } from 'try-catch-fn';

const status = tryCatch(() => {
  throw new Error('error');
});

console.log(status); // null

Readme

Keywords

Package Sidebar

Install

npm i try-catch-fn

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

2.7 kB

Total Files

7

Last publish

Collaborators

  • tariibaba