Catch exception throwed from assert function : assert : Development JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Development » assert »

 

Catch exception throwed from assert function

















<html>
    <head>
        <title>Try Catch Example</title>
        <script type="text/javascript">
                function assert(bCondition, sErrorMessage) {
                    if (!bCondition) {
                        throw new Error(sErrorMessage);
                    }
                }



                try {
                    assert(== 2"Two numbers are required.");
                catch (oException) {
                    alert(oException.message);      //outputs "Two numbers are required."
                }

        </script>
    </head>
    <body>
    </body>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Development
» assert