this

種類命令
書式
try
{
エラーの発生する可能性のある処理
}
catch(引数)
{
特定のエラー原因の場合の処理
}
finally
{
エラー全体の処理
}
解説
tryでエラーが発生する可能性のある命令、処理等を囲みます。エラーが発生した場合はcatch、finallyでエラー発生時の処理を行います。tryは入れ子(ネスト)にすることもできます。
サンプルコード
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<style type="text/css"><!--
body { margin:0px; }
form { position:absolute; top:10;left:10px; }
--></style>
<script type="text/javascript"><!--
window.onload = function()
{
try {
a = 1 / 0;
}
catch(e)
{
document.getElementById("txtField").value = "エラー内容("+e+")";
}
finally
{
document.getElementById("txtField2").value = "エラーが発生しました";
}
}
// --></script>
</head>
<body>
<img src="Default.png">
<form>
<input type="text" id="txtField" size=40"><br>
<input type="text" id="txtField2" size=40"><br>
</form>
</body>
</html>
実際のスクリプトをダウンロード