Error.parameterCount 関数
更新 : 2007 年 11 月
Sys.ParameterCountException 例外を表す Error オブジェクトを作成します。
var err = Error.parameterCount(message);
引数
- message
(省略可能) エラー メッセージ文字列。この値は null の場合もあります。message が null の場合は、既定のメッセージが使用されます。
戻り値
Error オブジェクト。
解説
parameterCount 関数を使用すると、無効な数の引数が関数に渡されたとき、例外が発生したことを通知できます。引数 message を使用すると、補足エラー情報を指定できます。
使用例
parameterCount 関数を使用して、Sys.ParameterCountException エラーを作成、スロー、およびキャッチする方法を次の例に示します。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Sample</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
<script type="text/javascript">
function throwAnError(a, b)
{
if (arguments.length !== arguments.callee.length)
{
// Throw a standard exception.
var err = Error.parameterCount("Invalid number of parameters attempted.");
throw err;
}
alert("No error occured.");
}
// Result: A Thrown Sys.ParameterCountException with the following message:
// Error: Sys.ParameterCountException: Invalid number of parameters attempted.
throwAnError(1,2,3,4);
</script>
</form>
</body>
</html>