JsDiagExceptionsInPromises_BreakOnFirstChanceExceptions.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /**exception(firstchance):stack();**/
  6. function unhandledPromiseRejection1() {
  7. Promise.resolve(true)
  8. .then(() => {
  9. throw new Error('error for unhandledPromiseRejection1')
  10. });
  11. }
  12. unhandledPromiseRejection1();
  13. function unhandledPromiseRejection2() {
  14. Promise.resolve(true)
  15. .then(() => {
  16. throw new Error('error for unhandledPromiseRejection2');
  17. })
  18. .then(() => {
  19. // no catch
  20. });
  21. }
  22. unhandledPromiseRejection2();
  23. function unhandledPromiseRejection3() {
  24. let p = Promise.resolve(true)
  25. .then(() => {
  26. throw new Error('error for unhandledPromiseRejection3');
  27. })
  28. .then(() => 0);
  29. p.then(() => 0).then(() => 1); // this path is not caught
  30. p.then(() => 2, (err) => { }); // this path is caught
  31. }
  32. unhandledPromiseRejection3();
  33. function unhandledPromiseRejection4() {
  34. let p = Promise.resolve(true)
  35. .then(() => {
  36. throw new Error('error for unhandledPromiseRejection3');
  37. })
  38. .catch((err) => {
  39. throw err;
  40. });
  41. }
  42. unhandledPromiseRejection4();
  43. function handledPromiseRejection5() {
  44. Promise.resolve(true)
  45. .then(() => {
  46. throw new Error('error for handledPromiseRejection5')
  47. }).catch(() => { });
  48. }
  49. handledPromiseRejection5();
  50. function handledPromiseRejection6() {
  51. Promise.resolve(true)
  52. .then(() => {
  53. throw new Error('error for handledPromiseRejection6');
  54. })
  55. .then(() => { }, () => { });
  56. }
  57. handledPromiseRejection6()
  58. function handledPromiseRejection7() {
  59. let p = Promise.resolve(true)
  60. .then(() => {
  61. throw new Error('error for handledPromiseRejection7');
  62. })
  63. .then(() => 0);
  64. p.then(() => 0).then(() => 1).catch(() => { }); // this path is caught
  65. p.then(() => 2, (err) => { }); // this path is caught
  66. }
  67. handledPromiseRejection7();
  68. function handledPromiseRejection8() {
  69. var p = Promise.resolve(0).then(() => {
  70. p.catch(() => { }); // lazily added catch on the currently executing promise
  71. throw new Error('error for handledPromiseRejection8');
  72. });
  73. }
  74. handledPromiseRejection8();
  75. function noRejection9() {
  76. let p = Promise.resolve(true)
  77. .then(() => {
  78. try {
  79. throw new Error('error for noRejection9');
  80. } catch (err) {
  81. }
  82. });
  83. }
  84. noRejection9();