Document directory
- Microsoft AJAX Library extends some static methods of Error to create specific errors:
- Attribute of the Error object:
- Error. create Function
- Error. popStackFrame Function
An Error is a built-in JS object that contains the Error information of JS during runtime. When an Error message is thrown, it can be captured through try {} catch (e.
Microsoft AJAX Library extends some static methods of Error to create specific errors:
Error. argument function
Create an Error object that indicates Sys. ArgumentException exception.
Error. argumentNull Function
Create an Error object that indicates Sys. ArgumentNullException exception.
Error. argumentOutOfRange Function
Create an Error object that indicates Sys. ArgumentOutOfRangeException.
Error. argumentType Function
Create an Error object that indicates Sys. ArgumentTypeException.
Error. argumentUndefined Function
Create an Error object that indicates Sys. ArgumentUndefinedException exception.
Error. invalidOperation Function
Create an Error object, which indicates that Sys. InvalidOperationException is abnormal.
Error. notImplemented Function
Create an Error object, which indicates that Sys. NotImplementedException is abnormal.
Error. parameterCount Function
Create an Error object that indicates Sys. ParameterCountException exception.
Error. format Function
Create an Error object that indicates a Sys. FormatException exception.
Attribute of the Error object:
Error. message Field
Indicates the description of the error.
Error. name field
Indicates the name used to identify the error.
Error. create Function
Create an Error object that contains an Error message.
You can use the create FUNCTION to create an Error object that contains additional Error information. You can use the message parameter to append information to an error. When an error occurs, the information can be displayed in the application. You can also use this parameter to provide detailed information for tracking errors. You can use the errorInfo parameter to add the Error information as a field to the Error object created by the function. In this way, you can specify custom error information to describe the error in more detail. The provided JavaScript Object must have a field named name, which contains a string that identifies an error. In the errorInfo object, extra fields of any type and name can be provided, which is very useful for custom exception handling.
/* Parammessage: (optional) error message string. ErrorInfo: (optional) JavaScript object instance, which contains error-related extension information. This object must have a name field, which contains a string with incorrect identifiers. This object can also contain fields that fully describe errors. Return: An Error object. */Var err = Error. create (message, errorInfo );
Sample Code:
function throwAnError(input) { if (input === undefined) { // Throw a standard exception type. var err = Error.argumentNull("input", "A parameter was undefined."); throw err; } else if (input === "Test1") { // Throw a generic error with a message. var messageVar = "A test message."; var err = Error.create(messageVar) throw err; } else if (input === "Test2") { // Throw a generic error with a message and associated errorInfo object. var messageVar = "This error contains an additional custom errorInfo object"; var errorInfoObj = { name: "SomeNamespace.SomeExceptionName", someErrorID: "436" }; var err = Error.create(messageVar, errorInfoObj); throw err; } alert("No error occured.");}throwAnError("Test2");
Error. popStackFrame Function
Update the fileName and lineNumber attributes of the Error instance to indicate the location where the Error is triggered rather than the location where the Error is created. Use this function to create a custom error type.
Some browsers are created based onErrorInstance location settingsErrorInstanceFileNameAndLineNumberField. IfErrorThis instance is caused outside the function range of the instance, which may cause problems.
Note::PopStackFrameMethod exception call caused by Microsoft AJAX Library. It should be called only when you define your own Error TypePopStackFrameMethod.
When you createErrorCallsPopStackFrameMethod,FileNameAndLineNumberField. The values of these fields are not created based on the location where the error is triggered.ErrorInstance location settings.PopStackFrameFunction updates based on the next frame in the browser stack traceErrorInstanceFileNameAndLineNumberField. This provides more accurate error information for debugging code.
Sample Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">