gfs-auto-trycatch
v1.0.2
Published
the base util to auto add try-catch wrap for Function or ClassMethod
Downloads
1
Readme
gfs-auto-trycatch-base
Auto add try-catch wrap for function base util.
Options
sourceRoot
: the code source root pathfilename
: in fact this option isfile path
filenameRelative
: file namesourceMap
: code source map file content, default isfalse
errorHandleFuncName
: error handler function name, default isGFS_TRY_CATCH_ERROR_HANDLE
,NOTE
: this function name must be defined global.
Usage
$ npm install gfs-auto-trycatch --save-dev
const autoTryCatch = require('gfs-auto-trycatch');
const codeContent = `
class Demo {
consturctor(){
this.name = "demo"
}
action(){
console.log('this name is: ', this.name)
}
}
`
const newCtn = autoTryCatch(codeContent, {});
console.log(newCtn);
// after add try catch
/*class Demo {
consturctor() {
try {
this.name = "demo";
} catch (_e) {
window.GFS_TRY_CATCH_ERROR_HANDLE && window.GFS_TRY_CATCH_ERROR_HANDLE(_e, "", "consturctor", 3, 2);
throw _e;
}
}
action() {
try {
console.log('this name is: ', this.name);
} catch (_e2) {
window.GFS_TRY_CATCH_ERROR_HANDLE && window.GFS_TRY_CATCH_ERROR_HANDLE(_e2, "", "action", 6, 2);
throw _e2;
}
}
}*/