Skip to content

Instantly share code, notes, and snippets.

@crongro
Created September 7, 2014 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crongro/b2a22970a97f8a98acf6 to your computer and use it in GitHub Desktop.
Save crongro/b2a22970a97f8a98acf6 to your computer and use it in GitHub Desktop.
javascript Error Handling
<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