• Call the specified function with zero or more individual arguments, the call will be wrapped in a try / catch block and the result returned wrapped in an ISafeReturn instance. If the function call throws an exception the error property will contain the exception otherwise the value property will contain the value returned from the function.

    Type Parameters

    • F extends ((...args: unknown[]) => any)

    Parameters

    • func: F

      The function to call

    • OptionalargArray: any[]

      An array of the arguments to pass to the function

    Returns ISafeReturn<F>

    The return value of the function or undefined if an exception is thrown

    0.10.5

    let result = safe((value: string) => {
    return JSON.parse(value);
    }, ["{ invalid: json value"]);

    // result.e instanceof SyntaxError

    let result2 = safe((value: string) => {
    return JSON.parse(value);
    }, ["{ valid: json value"]);