最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Get Last Javascript Error - Stack Overflow

programmeradmin5浏览0评论

I'm writing a bug reporter for my app. When something goes wrong, the user fills out a form and describes the problem and this is sent to the server. As part of the data collected in this form, I'd like to include the last javascript error. Is there any way to do this?

I'm writing a bug reporter for my app. When something goes wrong, the user fills out a form and describes the problem and this is sent to the server. As part of the data collected in this form, I'd like to include the last javascript error. Is there any way to do this?

Share Improve this question asked Jun 25, 2012 at 12:19 JudsonJudson 2,3254 gold badges19 silver badges20 bronze badges 1
  • you could insert your whole code in a try/catch block, which would catch everything that failed and didn't get catched before. – K.. Commented Jun 25, 2012 at 12:21
Add a comment  | 

3 Answers 3

Reset to default 8

You could implement a function to capture errors by using window.onerror (MDN documentation). That way the last error could be stored in window.localStorage or wherever you want and you could retrieve it again, when the bug report is filled.

you can use window.onerror

window.onerror = function(error, url, line) {
    //save errors here
};

You can assign a function to window.onerror and store the error information from the arguments.

发布评论

评论列表(0)

  1. 暂无评论