In php when we do some thing wrong then an error is shown with the line number where it has been committed. i want this same in javascript you will understand from my codes:
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)";
}
}
}
now look at the last throw
statement if the security is not "h"
or "l"
then it throws an exception as you can see.
Now suppose i am in my code editor on line says 90 and there i write private.str("abc",9000,"o");
where "o"
is not valid. so javascript should find that line where private.str("abc",9000,"o");
is written and then throw "Unexpected Security Level: Entered " +security+" is unexpected on line "+line_number+" and the default security level is low(l)";
and here for example line_number
is 90.
so javascript should throw this statement"Unexpected Security Level: Entered o is unexpected on line 90 and the default security level is low(l)";
I tried to search for this but none could help at my extent on knowledge
thanks!
you can use firebug or js console, or do it in code like this
var
line=(new Error).stack.split("\n")[4],
nr=line.slice(line.indexOf("at ")+2, line.length);
(How to get JavaScript caller function line number? How to get JavaScript caller source URL?)