前端代码异常捕获
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>前端代码异常捕获演示</title>
</head>
<body>
<input name="bn" type="button" onclick="myMethod();" value="捕获异常">
</body>
<script type="text/javascript">
function myMethod() {
var array = null;
try {
document.write(array[0]);
} catch(err) {
document.writeln("Error name: " + err.name + "");
document.write("<br>")
document.writeln("Error message: " + err.message);
}
}
</script>
</html>