@talesoft/rectangle
TypeScript icon, indicating that this package has built-in type declarations

0.1.1-alpha.0 • Public • Published

@talesoft/try-catch

A simple functional wrapper for a try-catch statement.

Makes it easier to handle exceptions immutably.

Usage

import tryCatch from '@talesoft/try-catch'

function somethingThatCanThrow() {

  if (amIWrong()) {

    throw new Error('I\'m wrong!')
  }

  return 'Some result'
}

const result = tryCatch(somethingThatCanThrow)

// result is of type `string | Error`

const alwaysResult = tryCatch(somethingThatCanThrow, () => 'Other result')

// alwaysResult is of type `string` ('Some result' or 'Other result')

const alwaysResult = tryCatch(somethingThatCanThrow, error => error.message)

// alwaysResult is of type `string` ('Some result' or 'I\'m wrong!')

/@talesoft/rectangle/

    Package Sidebar

    Install

    npm i @talesoft/rectangle

    Weekly Downloads

    5

    Version

    0.1.1-alpha.0

    License

    MIT

    Unpacked Size

    23.3 kB

    Total Files

    13

    Last publish

    Collaborators

    • torben-koehn
    • torbenkoehn
    • simonekruegel