Jump to content

Error Line Number


ShadowMage

Recommended Posts

Ok, here's another quick question. Is it possible to get the line number where a function is called. For example:

function aFunction() {   if (condition) {	  //do something   } else {	  throw "error line"+lineNumber;   }}...function anotherFunction() {   aFunction(); //Say this is line 47}

Is there a function or a property to set the lineNumber variable in the first function equal to line 47, the line where aFunction is called?

Link to comment
Share on other sites

There's not an easy way to do that. You can look at the arguments variable inside a function to see what's available in there, or you can try to create a new error object and then check the properties of that. http://stackoverflow.com/questions/1340872...script-caller-sThere's also an example of printing a stack trace here:http://github.com/emwendelin/javascript-stacktrace

Link to comment
Share on other sites

Ok, thanks. I'll have a look at those and see what I can find.Edit:Well, I've looked at those links and did a little messing around with it, and this appears to be far more complicated than I had hoped for. Thanks for your time, jsg.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...