19

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.

3
  • I also tried this: e.toString().replace(/(\r\n|\n|\r)/gm,"") without success Commented Jun 2, 2016 at 12:47
  • foreach(p in e){ console.log( e[p] ); } or JSON.stringify(e); could help? Check this answer. Commented Jun 2, 2016 at 12:48
  • It does not help. JSON.stringify(e) returns undefined. Commented Jun 2, 2016 at 12:54

2 Answers 2

24

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.

Sign up to request clarification or add additional context in comments.

Comments

12

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

1 Comment

Error.stack is not part of spec. It's present in most browsers, but not edge, and should not be relied on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.