17

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.

Vojtech Ruzicka
  • 16,384
  • 15
  • 63
  • 66
user1774309
  • 447
  • 1
  • 3
  • 14

2 Answers2

20

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.

Kulvar
  • 1,139
  • 9
  • 22
12

It seems that the Error Object has a property called stack. so, e.stack is the full text of the error.

user1774309
  • 447
  • 1
  • 3
  • 14
  • 3
    Error.stack is not part of spec. It's present in most browsers, but not edge, and should not be relied on. – ckersch Apr 15 '19 at 23:02