Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/codingbeautydev/try-catch-fn

Intuitive functional JavaScript try-catch
https://github.com/codingbeautydev/try-catch-fn

functional-programming javascript npm try-catch typescript

Last synced: about 1 month ago
JSON representation

Intuitive functional JavaScript try-catch

Awesome Lists containing this project

README

        

# try-catch-fn

Functional try-catch implementation.

More info here: [This is how functional try-catch transforms your JavaScript code](https://www.codingbeautydev.com/blog/javascript-functional-try-catch).

## Usage

```js
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.

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

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

console.log(status); // null
```