【发布时间】:2014-03-25 16:03:35
【问题描述】:
在 php 中,当我们做错事时,会显示一个错误,其中包含已提交的行号。我想在 javascript 中也一样,你会从我的代码中理解:
var varlist = {};
var private = {
str : function(nameArg, valueArg, security){
if (varlist.hasOwnProperty(nameArg) === true){
throw "Variable Existance : variable "+nameArg +" is already exist in your variable list and cannot be overwritten in private type";
}else if(security === "h"){
var stre = String(valueArg);
var strnew = stre.replace(/\d/g, "");
varlist[nameArg] = strnew;
}else if(security === "l"){
varlist[nameArg] = String(valueArg);
}else if(security !== "h" || security !== "n"){
varlist[nameArg] = String(valueArg);
throw "Unexpected Security Level: Entered " +security+" is unexpected and the default security level is low(l)";
}
}
}
现在查看最后一个throw 语句,如果安全性不是"h" 或"l",那么它会抛出异常,如您所见。
现在假设我在我的代码编辑器中在线显示 90,我在那里写了 private.str("abc",9000,"o");,其中 "o" 无效。所以javascript应该找到写private.str("abc",9000,"o");的那一行,然后抛出"Unexpected Security Level: Entered " +security+" is unexpected on line "+line_number+" and the default security level is low(l)";,这里例如line_number是90。
所以javascript应该抛出这个语句"Unexpected Security Level: Entered o is unexpected on line 90 and the default security level is low(l)";
我试图搜索这个,但在我的知识范围内没有一个可以帮助
谢谢!
【问题讨论】: