@trenskow/fail-silently

0.2.5 • Public • Published

@trenskow/fail-silently

A simple function wrapper for ignoring errors thrown.

Usage

You wrap the function you want to ignore errors thrown from as the example below.

const
	failSilently = require('@trenskow/fail-silently');

function myThrowingFunction(shouldThrow) {
    if (shouldThrow) throw new Error("This is my error.");
    return 'Hello, World!';
}

failSilently(myThrowingFunction)(false); // -> 'Hello, World!'
failSilently(myThrowingFunction)(true); // -> undefined

It also works with async functions.

LICENSE

See license in LICENSE

/@trenskow/fail-silently/

    Package Sidebar

    Install

    npm i @trenskow/fail-silently

    Weekly Downloads

    2

    Version

    0.2.5

    License

    BSD-2-Clause

    Unpacked Size

    4.85 kB

    Total Files

    7

    Last publish

    Collaborators

    • trenskow