Define
function MyError(code, message) {
this.code = code;
this.message = message;
Error.captureStackTrace(this, MyError);
}
util.inherits(MyError, Error);
MyError.prototype.name = 'MyError';
Raise
throw new MyError(777, 'Smth wrong');
Catch
if (err instanceof MyError) {
console.log(err.code, err.message);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…