try…catch 语句

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p id="demo"></p>
  6.  
  7. <script>
  8. try {
  9. adddlert("欢迎您,亲爱的用户!");
  10. }
  11. catch(err) {
  12. document.getElementById("demo").innerHTML = err.message;
  13. }
  14. </script>
  15.  
  16. </body>
  17. </html>