try-catchでわざと例外を発生させて、キャッチしてcatchロジックに移動する構文です。
IE8の場合、引数を二つ渡します。
throw new Error(-500,"エラーエラー");
Errorオブジェクトに引数を指定することにより任意のエラー番号、エラー説明を設定することができます。
以下、例です。アラートは表示されません。
以下、ソースです。
<html>
<head>
<title></title>
</head>
<body>
<script language="JavaScript">
<!--
function a(){
try{
throw new Error(-500,"エラーエラー");
alert("アラート");
}catch(e){
alert(e.number);
alert(e.description);
}
}
// -->
</script>
<input type="button" value="submit" onclick="a();">
</body></html>
Chrome23で例外を発生させる場合は引数をひとつ渡します。
throw new Error("Chromeエラー");
以下、ソースです。
<html>
<head>
<title></title>
</head>
<body>
<script language="JavaScript">
<!--
function b(){
try{
throw new Error("Chromeエラー");
alert("アラート");
}catch(e){
alert(e.stack);
}
}
// -->
</script>
<input type="button" value="submit" onclick="b();">
</body></html>