@zhaoyao91/try-catch
v0.0.0
Published
Return result and error instead of throwing.
Downloads
1
Readme
Try Catch
Return result and error instead of throwing.
Installation
npm i @zhaoyao91/try-catch
Usage
handle sync function
const tryCatch = require("@zhaoyao91/try-catch");
function fn(...args) {
// throw or return
}
const [error, result] = tryCatch(fn, ...args);
handle async function
const tryCatch = require("@zhaoyao91/try-catch");
async function fn(...args) {
// throw or return
}
const [error, result] = await tryCatch(fn, ...args);
Customize promise judge logic
require("@zhaoyao91/try-catch").isPromise = function(x) {
// customized logic to tell if x is a promise
};
License
MIT