funcx
v1.1.5
Published
A javascript module to easily catch errors.
Downloads
10
Readme
funcX
Catch javascript errors easily
install:
$ npm install funcx
##requiring: if you want also using "Method 1"
const funcx = require("funcx")(Function);
else :)
const funcx = require("funcx")();
Method 1:
Catch errors with this syntax:
[yourFunction].funcx([arguments])("callback function")
example
const funcx=require("funcx")(Function);
function sum(a,b,c) {
console.log(a+b+c);
}
sum.funcx(1,5,7);
and outout of this code is: 13, if any errors occurred you can catch it like this:
const funcx=require("funcx")(Function);
function sum(a,b,c) {
console.log(a+b+c,d);
}
sum.funcx(1,5,7)(err=>{
console.log(err)
});
output:
ReferenceError: d is not defined
at sum.....
Returned error is an object that like returned "e" in try/catch. so you can use
err.name
err.message
...
Method 2:
like Method 1 but in different syntax:
funcx(yourfunction)(arguments)("callback function");
example
const funcx=require("funcx")();
function sum(a,b,c) {
console.log(a+b+c,d);
}
funcx(sum)(3,4,7)(err=>{
console.log(err)
});
Method 3:
catch errors near function instead when calling it:
example
const funcx=require("funcx")(Function);
function sum(a,b,c) {
console.log(a+b+c,d);
}
sum.onErr=function(err){ ///when error occurred, this function called
console.log(err)
};
funcx(sum)(3,4,7);
/// or
sum.funcx(3,4,5);