try-catch

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
1
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
N/A
`tryCatch` takes two functions, a `tryer` and a `catcher`.
1 contributor
Install try-catch as a package?
Copied
npm i @bit/justin-capalbo.ramda.try-catch
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
tryCatch (
tryer:Function,
catcher:Function
) : Function

tryCatch takes two functions, a tryer and a catcher. The returned function evaluates the tryer; if it does not throw, it simply returns the result. If the tryer does throw, the returned function evaluates the catcher function and returns its result. Note that for effective composition with this function, both the tryer and catcher functions must return the same type of results.

Example
R.tryCatch(R.prop('x'), R.F)({x: true}); //=> true
     R.tryCatch(() => { throw 'foo'}, R.always('catched'))('bar') // => 'catched'
     R.tryCatch(R.times(R.identity), R.always([]))('s') // => []
``
Arguments
tryer: Function

The function that may throw.

catcher: Function

The function that will be evaluated if tryer throws.

Returns
Function

A new function that will catch exceptions and send then to the catcher.

Help and resources