自定义异常类型

新手上路,请多包涵

我可以在 JavaScript 中为用户定义的异常定义自定义类型吗?如果是这样,我该怎么做?

原文由 Manki 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 226
1 个回答

来自 网络参考

 throw {
  name:        "System Error",
  level:       "Show Stopper",
  message:     "Error detected. Please contact the system administrator.",
  htmlMessage: "Error detected. Please contact the <a href=\"mailto:sysadmin@acme-widgets.com\">system administrator</a>.",
  toString:    function(){return this.name + ": " + this.message;}
};

原文由 jon077 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题