JavaScript中的自定义异常 [英] Custom Exceptions in JavaScript
本文介绍了JavaScript中的自定义异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在JavaScript中为用户定义的异常定义自定义类型吗?如果可以,我该怎么做?
Can I define custom types for user-defined exceptions in JavaScript? If I can, how would I do it?
推荐答案
来自: http://www.webreference.com/programming/javascript/rg32/2.html
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;}
};
这篇关于JavaScript中的自定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文