try-catch in JavaScript : how to get stack trace or line number of the original error
Posted
by
Greg Bala
on Stack Overflow
See other posts from Stack Overflow
or by Greg Bala
Published on 2012-06-11T22:04:18Z
Indexed on
2012/06/11
22:40 UTC
Read the original article
Hit count: 269
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!
© Stack Overflow or respective owner