Skip to content

codingbeautydev/try-catch-fn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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