Function invoked if initial function throws an error.
Function invoked if initial function throws an error.
If a function does not throw, returns the function return value; otherwise, returns the return value of a second function y
.
The function y
is provided a single argument:
x
function to try invoking
function to invoke if a function throws
the return value of either x
or y
var randu = require( `@stdlib/random/base/randu` );
function x() {
if ( randu() < 0.5 ) {
throw new Error( 'beep' );
}
return 1.0;
}
function y() {
return randu();
}
var z = trythen( x, y );
// returns <number>
Function invoked if initial function throws an error.
the error thrown by
x
return value of
trythen
function