Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/try-then/docs/types/index.d"

Index

Type aliases

Functions

Type aliases

ErrorHandler

ErrorHandler: Nullary | Unary

Function invoked if initial function throws an error.

param

the error thrown by x

returns

return value of trythen function

Nullary

Nullary: () => any

Function invoked if initial function throws an error.

returns

return value of trythen function

Type declaration

    • (): any
    • Returns any

Unary

Unary: (err: Error) => any

Function invoked if initial function throws an error.

param

the error thrown by x

returns

return value of trythen function

Type declaration

    • (err: Error): any
    • Parameters

      • err: Error

      Returns any

Functions

Export assignment trythen

  • If a function does not throw, returns the function return value; otherwise, returns the return value of a second function y.

    Notes

    • The function y is provided a single argument:

      • error: the error thrown by x

    Parameters

    • x: Function

      function to try invoking

    • y: ErrorHandler

      function to invoke if a function throws

    Returns any

    the return value of either x or y

    Example

    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>