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 ¯_(ツ)_/¯
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)
Generated using TypeDoc
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 ¯_(ツ)_/¯