Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Functions

Functions

wrap

  • wrap(fcn: Function, thisArg?: any): Function
  • Wraps a function in a try/catch block.

    Notes

    • If provided an asynchronous function, the returned function only traps errors which occur during the current event loop tick.
    • If a function throws a literal, the literal is serialized as a string and returned as an Error object.

    Parameters

    • fcn: Function

      function to wrap

    • Optional thisArg: any

      function context

    Returns Function

    wrapped function

    Example

    function fcn() {
        throw new Error( 'beep boop' );
    }
    
    var f = wrap( fcn );
    
    var out = f();
    if ( out instanceof Error ) {
        console.error( out.message );
        // => 'beep boop'
    }