Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Functions

Functions

Export assignment trycatch

  • trycatch(x: Function, y: any): any
  • If a function does not throw, returns the function return value; otherwise, returns y.

    Parameters

    • x: Function

      function to try invoking

    • y: any

      value to return if a function throws

    Returns any

    either the return value of x or the provided argument y

    Example

    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>