JS how to convert to string the Error Object from the window.error?

user1774309 picture user1774309 · Jun 2, 2016 · Viewed 13.2k times · Source

I implemented:

 window.onerror = function (m, s, l, c, e) {
 }

Where the e is the Error Object. For example, it contains:

ReferenceError: rde is not defined
    at Object.bla.cs (domain.pt/bla.js:418:17)
    at n.aanv (domain.pt/bla.js:125:29)

If i make e.toString(), only the first line is returned. How to get the 3 lines? Thank you.

Answer

Kulvar picture Kulvar · Jun 2, 2016

Error object have a .message property containing the full message (no need for .toString(). There is also .stack but it's not a standardized property.