Jump to content

Error Line Number


ShadowMage
 Share

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.

Edited by jkloth
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...