Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

Error Type Extensions

Provides static functions that extend the built-in ECMAScript (JavaScript) Error Object type by including exception details and support for application-compilation modes (debug or release).

Namespace: None. This type extension is global and not part of a namespace.

Inherits: None

Syntax

var err = Error.create(message, errorInfo);

Extension Functions

Name

Description

argument Function

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

argumentNull Function

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

argumentOutOfRange Function

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

argumentType Function

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

argumentUndefined Function

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

create Function

Creates an Error object that has optional additional error information.

invalidOperation Function

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

notImplemented Function

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

parameterCount Function

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

popStackFrame Function

Updates the fileName and lineNumber properties of an Error instance to indicate where the error was thrown instead of where the error was created. Use this function if you are creating custom error types.

Remarks

Error extensions are part of the Microsoft AJAX Library. They add functionality to the built-in JavaScript Error object.

Error Types

The Error type extensions generate an Error type with additional fields that represent the exception details. All Error type extensions add at least a name field to identify the exception. You can test the exception's name field to determine what action to take.

The following example shows how to test the Error,name property for the ArgumentNullException exception.

try{ } 
catch (e) {
    if (e.name === "Sys.ArgumentNullException"){
        // Code here ot handle exception.
    }
}

For more information about the JavaScript object that this type extends, see Error Object in the JScript Language Reference.

Optimizing Client-Script Error Handling for Debug and Release Modes

The Microsoft ASP.NET AJAX Error object extensions provide additional client-script error handling functionality.

Microsoft ASP.NET AJAX provides debug and release application-compilation modes. This enables you to throw exceptions in debug scripts that are helpful to the debugging process, while minimizing the size of release code to emphasize performance. Microsoft ASP.NET AJAX provides additional error-handling features in debug mode, such as type checking and argument checking, and provides more detailed error messages than in release mode.

For more information, see How to: Enable Debugging for ASP.NET Applications and ASP.NET AJAX Debugging and Tracing Overview.

Example

The following example shows how to create a new Error instance by invoking the create method of the ASP.NET AJAX Error Object object.

JavaScript

function validateNumberRange(input, min, max) 
{

    // Verify the required parameters were defined.
    if (input === undefined)
    {
        // Throw a standard exception type.
        var err = Error.argumentNull("input", "A parameter was undefined."); 
        throw err;
    }
    else if (min === undefined)
    {
        var err = Error.argumentNull("min", "A parameter was undefined."); 
        throw err;
    }
    else if (max === undefined)
    {
        var err = Error.argumentNull("max", "A parameter was undefined."); 
        throw err;
    }
    else if (min >= max)
    {
        var err = Error.invalidOperation("The min parameter must be smaller than max parameter.");
        throw err;
    }
    else if (isNaN(input))
    {
        msg = "A number was not entered.  ";
        msg += String.format("Please enter a number between {0} and {1}.", min, max);

        var err = Error.create(msg);
        throw err;
    }
    else if (input < min || input > max)
    {
        msg = "The number entered was outside the acceptable range.  ";
        msg += String.format("Please enter a number between {0} and {1}.", min, max);

        var err = Error.create(msg);
        throw err
    }

    alert("The number entered was within the acceptable range.");
}


var input = undefined;
var min = -10;
var max = 10;

// Result: A thrown ErrorArgumentNull exception with the following Error object message:
// "Sys.ArgumentNullException: A parameter was undefined. Parameter name: input"
validateNumberRange(input, min, max);