/sidekicker

A lib for Typescript/Javascript to help you in any project

Primary LanguageTypeScriptGNU General Public License v3.0GPL-3.0

sidekicker

Methods

tryCatch

A simple implementation of tryCatch, inspired in Java Exceptions+TryCatch.

const sum = tryCatch(
    (x: number) => {
        if (x === 1) throw new CustomError()
        if (x === 2) throw () => {
        };
        if (x === 3) throw "==>"
        return 1 + 1
    },
    // Will call this function if the throw==CustomError
    exception(CustomError, (e) => `THIS IS A ${e.name}`),
    // Will call this function if throw a function
    exception(Function, (e) => `THIS IS A __${e.constructor.name}__ ERROR`),
    // Will call this function if throw a string
    exception(String, (e) => `${e} string error`),
)