Catch the error and handling try-catch

<! DOCTYPE HTML > 
< HTML lang = "EN" > 
< head > 
    < Meta charset = "UTF-. 8" > 
    < Meta name = "the viewport" Content = "width = Device-width, Initial-Scale = 1.0" > 
    < Meta HTTP-equiv = "X--the UA-Compatible" Content = "IE = Edge" > 
    < title > capture error handling and the catch-the try </ title > 
    <-!  
        the try codes {a} catch (name)) {Code b} if confirm (information 1) codes {c} else {d} Code
        Interpretation: 1) When no error code is a code b is not performed
             2) try attempt to execute {codes a}, when an error occurs; the catch capture execute {Code b} error (name) after, 
                and Display (message 1 page) is executed (code c after the user points is determined), the user clicks Cancel after executing (code d); 
        if a try code there is no error, a code that is executed 
        if a try code errors, a code that is not executed, the code execution b catch directly 
        in this way to process the code error 

        Meanwhile, can be combined confirm () method of interaction with the user 
        when an error occurs, the execution code B, and generates a dialog box to display information and "OK" / "cancel" button 
        if the user points is determined, c is the code executed 
        if the user click cancel, then execute the code d 

        Remember: when an error is generated, JavaScript can actually create an error object with two properties: name and message. 
     -> 
</ head > 
< body > 
    < Script > 
        var B = 0 ;
         the try { 
            the console.log (A); //A variable does not exist, an error occurs 
        }
         the catch (ERR) { // the catch () capture name = ERR error 
            the console.log (B = . 1 ); // this code is executed to correct the error 
            IF (Confirm ( " right or wrong? " )) { // pop-up dialog box displays the message "right or wrong?" and "OK" / "cancel" button 
                document.write ( " on " ); // press "OK", page output "to" 
            } the else { 
                document.write ( " wrong " ); // press "cancel", page output "error" 
            } 
        } 
    </ Script >
</body>
</html>

Guess you like

Origin www.cnblogs.com/vinson-blog/p/12040306.html