function to try invoking
value to return if a function throws
either the return value of x
or the provided argument y
var randu = require( `@stdlib/random/base/randu` );
function x() {
if ( randu() < 0.5 ) {
throw new Error( 'beep' );
}
return 1.0;
}
var z = trycatch( x, -1.0 );
// returns <number>
If a function does not throw, returns the function return value; otherwise, returns
y
.