Exception.lineNumber returns "undefined" in Google Chrome and Internet Explorer

I need to get fileName, Message, LineNumber, etc. from javascript exception. I tried the following code.

try {
  alertt("dddd");
} catch (e) {
  console.log("ExceptionType: "+ e.name);
  console.log("Message: "+ e.message);
  console.log("Line No: "+ e.lineNumber);
}

I got the following result in Mozilla Firefox

ExceptionType: ReferenceError
Message: alertt not defined
Row Number: 4

But the same code gave the following result in Google Chrome, Internet Explorer

ExceptionType: ReferenceError
Message: alertt not defined
Row number: undefined

It does not give a line number. How to solve this problem? Is there any other way to get the line number?

e.stack. . Google Chrome

 ReferenceError: alertt is not defined
    at message (http://localhost/ems-test/js/test.js:4:4)
    at HTMLDocument.<anonymous> (http://localhost/ems-test/js/test.js:14:2)
    at c (http://localhost/ems-test/js/jquery-1.10.2.min.js:4:26036)
    at Object.p.fireWith [as resolveWith] (http://localhost/ems-test/js/jquery-1.10.2.min.js:4:26840)
    at Function.x.extend.ready (http://localhost/ems-test/js/jquery-1.10.2.min.js:4:3305)
    at HTMLDocument.q (http://localhost/ems-test/js/jquery-1.10.2.min.js:4:717) 

firefox

message@http://localhost/ems-test/js/test.js:4
@http://localhost/ems-test/js/test.js:14
x.Callbacks/c@http://localhost/ems-test/js/jquery-1.10.2.min.js:4
x.Callbacks/p.fireWith@http://localhost/ems-test/js/jquery-1.10.2.min.js:4
.ready@http://localhost/ems-test/js/jquery-1.10.2.min.js:4
q@http://localhost/ems-test/js/jquery-1.10.2.min.js:4

. . . . , . .

?

+4
2
window.onerror = function (msg, url, line) {
   alert("Message : " + msg );
   alert("url : " + url );
   alert("Line number : " + line );
}

, . : http://www.tutorialspoint.com/cgi-bin/practice.cgi?file=javascript_40

+1

IE , ; Chrome , , e.stack . , console.dir(e) catch.

0

All Articles