Created
September 7, 2014 02:59
-
-
Save crongro/b2a22970a97f8a98acf6 to your computer and use it in GitHub Desktop.
javascript Error Handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div>a</div> | |
</body> | |
</html> | |
<script> | |
try { | |
var a; | |
a.push(); | |
} catch(e) { | |
alert("try catch error" + e.message); | |
} | |
//비동기 로직은 try~catch로 잡히지 않는다. | |
try { | |
setTimeout(function(){ | |
var a; | |
a.sort(); | |
},1000); | |
}catch(e) { | |
alert("try on setTimeout " +e); | |
} | |
document.body.addEventListener("click", function(e){ | |
var c = 0; | |
c.read(); | |
alert(c); | |
}); | |
//아래에 두고 비동기 오류만 잡도록 한다. | |
window.onerror = function(e){ | |
alert("error : " + e); | |
} | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment