Mobile Web development process, in the real machine testing, often encounter some PC debugging can not reproduce the problem, at this time we need to intercept the phone on the error, and have the corresponding output.
Companies and the Internet have similar tools/class libraries, but if a simple debugging, perhaps do not need to introduce tools or class libraries, we need to know the principle of global interception.
It's really simple, window.onerror.
Grammar:
Onerror=handleerr
function Handleerr (msg,url,l)
{
Handle the error here
return TRUE or False
}
Whether the browser displays standard error messages depends on the return value of the onerror. If the return value is False, an error message is displayed in the console (JavaScript console). Conversely, it is not.
Instance:
The following example shows how to use the OnError event to catch an error:
In addition, if we want to simulate this process directly in the chrome console, we find that using throw new Error directly will not trigger this onerror, perhaps because the console environment is not the same as the page environment.
But in a different way, you can trigger:
settimeout (function () {throw new Error}, 1000)
That's smart.