Partager via


Error.parameterCount Function

Creates an Error object that represents the Sys.ParameterCountException exception.

var err = Error.parameterCount(message);

Arguments

  • message
    (Optional) An error message string. The value can be null. If message is null, a default message is used.

Return Value

An Error object.

Remarks

The parameterCount function lets you communicate that an exception has occurred when an invalid number of arguments have been passed to a function. The message argument enables you to specify additional error information.

Example

The following example shows how to create, throw, and catch a Sys.ParameterCountException error by using the parameterCount function.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://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>

See Also

Reference

Error Type Extensions

Concepts

Debugging and Tracing Ajax Applications Overview

Other Resources

Language Reference