Get the actual Javascript Error object with [removed]

前端 未结 3 796
有刺的猬
有刺的猬 2020-12-13 08:34

Javascript has this great callback window.onerror. It\'s quite convenient to track any error. However, it calls with the error name, the file name and the line.

3条回答
  •  感动是毒
    2020-12-13 09:01

    If you're referring to stack trace of the error object, then AFAIK, this is not possible.

    Simple reason being that a stack trace is related to an execution context in which runtime exceptions (handled with try...catch...finally) were created or thrown (with new Error() or throw).

    Whereas when window.onerror is invoked, it is called within a different context.

    You can get some mileage by inspecting window.event (not available on FF) in your onerror handler.

提交回复
热议问题