SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 107 | Next

Robin Pars, Laurence Moroney, and John Grieb

"Foundations of ASP.NET AJAX"

You can use the Error.argumentNull
method to generate an exception of that type by passing the name of the missing parameter
and a description as shown here:
Error.argumentNull("x", "The x parameter was not provided.");
Also, suppose you had implemented the classic try/catch block in your JavaScript,
and checking for a necessary condition turned out to be false. You can generate a custom
typed exception for proper handling later. The create method is all that is needed to create
a custom exception as shown in the following GenerateError function:
function GenerateError() {
try
CHAPTER 4 ?–  ASP.NET AJAX CLIENT LIBRARIES 60
{
throw Error.create('A custom error was generated');
}
catch(e)
{
alert(e.message);
}
}
Running the function displays the error message to the user as shown in Figure 4-3.
Figure 4-3. Displaying a custom generated error
Consequently, if you needed to have additional properties in the custom exception,
you provide another object to the create method, which contains a list of key/value pairs
to the create method such as those illustrated in the following script:
var errParms = {source: 'GenerateError', ErrorID: '999'};
Error.


Pages:
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119