UNPKG

@thatcompany/ts-tool

Version:

基于TypeScript编写的工具库

32 lines 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmptyError = void 0; class EmptyError extends Error { printStack; handle = () => { }; // 静态属性,用于存储全局默认的 handle 函数 static defaultHandle = () => { }; /** * 构造函数 * @param param 错误参数 */ constructor(param = { message: '', printStack: false, handle: Function, }) { super('EmptyError => ' + param.message); this.printStack = param.printStack || false; this.handle = param?.handle?.bind(this) || EmptyError.defaultHandle; Error.captureStackTrace(this, this.constructor); // 捕获堆栈 this.name = this.constructor.name; // 将错误名称设置为类名 this.printStack || (this.stack = ''); // 清空堆栈信息 this.handle(this); } // 静态方法,设置默认的 handle 函数 static setDefaultHandle(handle) { EmptyError.defaultHandle = handle; } } exports.EmptyError = EmptyError; //# sourceMappingURL=EmptyError.js.map