function MyError(msg){
  this.name="MyError";
  this.message = msg || "自定义异常的默认消息";
}

MyError.prototype = Object.create(Error.prototype);

MyError.prototype.constructor = MyError

 

 

try{

  throw new MyError("xiaol")

}catch(e){

  console.log(e.name+":"+e.message)

}

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2021-07-06
  • 2021-05-12
  • 2022-02-10
  • 2022-02-10
猜你喜欢
  • 2021-09-26
  • 2022-01-09
相关资源
相似解决方案