Quantcast
Viewing all articles
Browse latest Browse all 10

Using Global Namespace Error Type

In this example we will use the Error Type static extension methods that get added to the base ECMAScript (JavaScript) Error type when using the Microsoft AJAX Client Library.

To use the Microsoft AJAX Client Library you need to add a ScriptManager control within the Form tags of your WebForm.

        function validatePassword(password) {

            try {

                if (password == undefined) {

                    var cause = Error.argumentUndefined("password", "Password was undefined.");
                                       
                    throw cause;
                }
                else if (password == '') {

                    var cause = Error.argumentNull("password", "Password was empty.");              

                    throw cause;
                }               
                else if (password.length < 6) {

                    var cause = Error.argumentOutOfRange("The password must be longer than 6 characters.");
                    
                    throw cause;
                }
                else if (password.length > 12) {

                    var cause = Error.argumentOutOfRange("The password must be less than 12 characters.");

                    throw cause;
                }
                else if (password == 'password') {

                    var cause = Error.invalidOperation("The password must not be the word password.");

                    throw cause;
                }
                else if (password == 123456789) {

                    var cause = Error.notImplemented("This password validation has not been completed yet.");

                    throw cause;
                }
                
                alert("Password: " + password + " is OK!");                

            } catch (e) {
                alert(e.message);
            }
        }

You can download the Using Global Namespace Error Type project here


Viewing all articles
Browse latest Browse all 10

Trending Articles