try2.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // basic try/catch testcases, including functions
  6. function print(x)
  7. {
  8. WScript.Echo(x);
  9. }
  10. function f(n, str)
  11. {
  12. try
  13. {
  14. if(n == 0)
  15. throw str;
  16. else
  17. f(n-1, str);
  18. }
  19. finally
  20. {
  21. print("f(" + n + "): " + str);
  22. }
  23. }
  24. try
  25. {
  26. f(10, "test 1");
  27. }
  28. catch(a)
  29. {
  30. print(a);
  31. }
  32. try {
  33. throw "Hello";
  34. }
  35. catch (e)
  36. {
  37. with({}) { print(e); }
  38. }
  39. var d = {toISOString:1,toJSON:Date.prototype.toJSON};
  40. try {
  41. d.toJSON()
  42. }
  43. catch(e)
  44. {
  45. with({})
  46. {
  47. print(e);
  48. }
  49. }
  50. var a = "global";
  51. try
  52. {
  53. throw "abc";
  54. }
  55. catch(e)
  56. {
  57. eval("var a = 'catch-local';")
  58. }
  59. print(a);