捕捉浏览器中的JS运行时错误,主要通过监听window.onerror来实现。但是对于不同的脚本执行方式以及不同的浏览器,能捕获到的信息会有区别。
window.onerror 讲接收3个参数:
msg:错误描述,比如:a is not definedurl:出错脚本所在的urllineNumber:出错脚本的行数
本文将对不同浏览器和不同的脚本执行方式进行测试,并总结这些区别。
| 王 | |
| 江 | |
| 周 | |
| 胡 | |
| 刘 | |
| 李 | |
| 吴 | |
| 毛 | |
| 温 | |
| 习 |
| <!DOCTYPE HTML> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <!--允许全屏--> | |
| <meta content="yes" name="apple-mobile-web-app-capable"/> | |
| <meta content="yes" name="apple-touch-fullscreen"/> | |
| <!--禁止电话号码和邮箱识别--> |
| var fs = require('fs'), | |
| http = require('http'); | |
| var Promise = function(values) { | |
| this._callbacks = []; | |
| this._errbacks = []; | |
| if (arguments.length > 0) { | |
| this.fulfill.apply(this, values); | |
| } | |
| } |
| var callA = function (callback) { | |
| setTimeout(function () { | |
| callback({name: "a", data: "I am result A"}); | |
| }, Math.round(Math.random() * 300)); | |
| }; | |
| var callB = function (callback) { | |
| setTimeout(function () { | |
| callback({name: "b", data: Math.round(Math.random() * 300)) % 2 === 0}); | |
| }, Math.round(Math.random() * 300)); |
捕捉浏览器中的JS运行时错误,主要通过监听window.onerror来实现。但是对于不同的脚本执行方式以及不同的浏览器,能捕获到的信息会有区别。
window.onerror 讲接收3个参数:
msg:错误描述,比如:a is not definedurl:出错脚本所在的urllineNumber:出错脚本的行数本文将对不同浏览器和不同的脚本执行方式进行测试,并总结这些区别。
| data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script> |
| Copyright (c) 2013 Ross Kirsling | |
| Permission is hereby granted, free of charge, to any person obtaining | |
| a copy of this software and associated documentation files (the | |
| "Software"), to deal in the Software without restriction, including | |
| without limitation the rights to use, copy, modify, merge, publish, | |
| distribute, sublicense, and/or sell copies of the Software, and to | |
| permit persons to whom the Software is furnished to do so, subject to | |
| the following conditions: |
| #!/usr/bin/python | |
| #coding=utf-8 | |
| import sqlite3 | |
| import os | |
| from lxml import etree | |
| def get_notes(ever_enex): | |
| '''extract notes from .enex file''' | |
| content = open(ever_enex, 'r').read() |
| ; Stumbling towards Y (Clojure Version) | |
| ; | |
| ; (this tutorial can be cut & pasted into your IDE / editor) | |
| ; | |
| ; The applicative-order Y combinator is a function that allows one to create a | |
| ; recursive function without using define. | |
| ; This may seem strange, because usually a recursive function has to call | |
| ; itself, and thus relies on itself having been defined. | |
| ; | |
| ; Regardless, here we will stumble towards the implementation of the Y combinator. |
| #!/usr/bin/env python | |
| # coding:utf-8 | |
| import _env | |
| from time import time | |
| from urllib import urlencode | |
| from urllib2 import urlopen as urlopen2 | |
| from urlparse import parse_qsl | |
| from hashlib import md5 | |
| from urlgrabber import urlopen | |
| import errno |