Error.parameterCount 函数

更新:2007 年 11 月

创建一个 Error 对象,该对象表示 Sys.ParameterCountException 异常。

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>


请参见

概念

调试和跟踪 AJAX 应用程序概述

参考

Error 类型扩展

其他资源

语言参考