try-catch in JavaScript : how to get stack trace or line number of the original error
- by Greg Bala
When using TRY-CATCH in JavaScript, how to get the line number of the line that caused the error?
On many browsers, the below code will work great and I will get the stack trace that points to the actual line that throw the exception.
However, some browsers do not have "e.stack". Iphone's safari is one example.
Is there someway to get the line number that will work for all browsers?
try
{
// lots of code here
var i = v.WillGenerateError; // how to get this line number in catch??
// lots of code here
}
catch (e)
{
alert (e.stack) // this will not work on iPhone, for example
}
Many thanks!