Skip to content

Instantly share code, notes, and snippets.

@snaka
Created October 12, 2008 11:58
Show Gist options
  • Save snaka/16393 to your computer and use it in GitHub Desktop.
Save snaka/16393 to your computer and use it in GitHub Desktop.
<html><head><title>Javascript try..catch statement test code</title>
<script type="text/javascript">
output = null;
window.onload = function() {
output = document.getElementById('output');
log('loaded');
}
function log(msg) {
var line = document.createElement('div');
line.innerHTML = msg;
output.appendChild(line);
}
function test() {
log('test start');
try {
log('outer try block ...');
try {
log('inner try block...');
throw 'ERROR';
log('end of try block');
}
catch(ex) {
log('catch block recive : ' + ex);
throw 'inner ERROR'
}
finally {
log('finally block');
}
log('exit from inner try .. catch .. finally');
}
catch(ex) {
log('catch outer recieve : ' + ex);
}
finally {
log('finally outer');
}
log('exit from try .. catch .. finally');
}
/*---------------------------------------
== RESULT ==
loaded
test start
outer try block ...
inner try block...
catch block recive : ERROR
finally block
catch outer recieve : inner ERROR
finally outer
exit from try .. catch .. finally
------------------------------------------*/
</script>
</head>
<body>
<h1>Try ... catch statment test.</h1>
<button onclick="test()">GO!</button>
<div id="output">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment