nullableTryCatch
nullableTryCatch asynchronously runs the function passed to it and returns its return value if everything goes right. If an error is thrown, it returns null
Import
import { nullableTryCatch } from '@fullstacksjs/toolbox';
Signature
function nullableTryCatch<T>(fn: (...args: any[]) => T): T | null
Examples
If there are no errors:
const execute = () => 'ok';
nullableTryCatch(execute); // 'ok'
If there is an error:
const execute = () => {
throw 'Unknown Error';
};
nullableTryCatch(execute); // null