try…catch 语句

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. var txt=""
  5. function message()
  6. {
  7. try
  8. {
  9. adddlert("Welcome guest!")
  10. }
  11. catch(err)
  12. {
  13. txt="本页中存在错误。\n\n"
  14. txt+="错误描述:" + err.description + "\n\n"
  15. txt+="点击“确定”继续。\n\n"
  16. alert(txt)
  17. }
  18. }
  19. </script>
  20. </head>
  21.  
  22. <body>
  23. <input type="button" value="查看消息" onclick="message()" />
  24. </body>
  25.  
  26. </html>