Options
All
  • Public
  • Public/Protected
  • All
Menu

Module function/tryCatch

Index

References

Functions

References

Renames and re-exports tryCatch

Functions

  • Takes two functions, tryer and catcher.

    Returns a function that, when invoked with zero or more parameters, calls the tryer with those parameters, and if tryer throws, calls the catcher with the error as first argument and original arguments as rest. If that still throws, then ¯_(ツ)_/¯

    example
     tryCatch(x => x.length, () => 0)([ 1, 2, 3 ]) // 3
    tryCatch(x => x.length, () => 0)( undefined ) // 0
    tryCatch(
    someDataTransform,
    (err, ...rest) => {
    logAsyncToServer('someDataTransform failed', err, 'with arguments', rest);
    return DEFAULT_VALUE;
    }
    )( someIncompleteData ) // DEFAULT_VALUE (error is logged somewhere)

    Type parameters

    • T

    Parameters

    Returns Func<T>

Generated using TypeDoc