PromiseRejectionEvent() constructor returns a newly created PromiseRejectionEvent , which represents events fired when a JavaScript Promise is rejected. With promise rejection events, it becomes possible to detect and report promises which fail and whose failures go unnoticed. It also becomes easier to write a global handler for errors.

There are two types of PromiseRejectionEvent : unhandledrejection is sent by the JavaScript runtime when a promise is rejected but the rejection goes unhandled. A rejectionhandled event is emitted if a promise is rejected but the rejection is caught by a rejection handler..

句法

promiseRejectionEvent = PromiseRejectionEvent(type, options);
					

参数

PromiseRejectionEvent() constructor also inherits parameters from Event() .

type
A string representing the name of the type of the PromiseRejectionEvent . This is case-sensitive and should be one of "rejectionhandled" or "unhandledrejection" , to match the event names of the possible (non-synthetic) PromiseRejectionEvent events that user agents can actually fire).
选项
对象 specifying details about the rejection which occurred:
promise
Promise that was rejected.
reason
Any value or 对象 which represents the reason the promise was rejected. This can be anything from a numeric error code to an error DOMString to an object which contains detailed information describing the situation resulting in the promise being rejected.

返回值

新的 PromiseRejectionEvent configured as specified by the parameters.

范例

This example creates a new unhandledrejection event for the promise myPromise with the reason being the string "My house is on fire". The reason could just as easily be a number, or even an object with detailed information including the home address, how serious the fire is, and the phone number of an emergency contact who should be notified.

let myRejectionEvent = new PromiseRejectionEvent("unhandledrejection", {
  promise : myPromise,
  reason : "My house is on fire"
});
								

规范

规范 状态 注释
HTML 实时标准
The definition of 'the PromiseRejectionEvent interface' in that specification.
实时标准 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
PromiseRejectionEvent() 构造函数 Chrome 49 Edge ≤79 Firefox 69
69
Disabled ). To change preferences in Firefox, visit
IE No Opera 36 Safari 11 WebView Android 49 Chrome Android 49 Firefox Android 68 Opera Android 36 Safari iOS 11.3 Samsung Internet Android 5.0

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改:
  1. PromiseRejectionEvent
  2. 构造函数
    1. PromiseRejectionEvent()
  3. 特性
    1. promise
    2. reason
  4. 继承:
    1. 事件
  5. HTML DOM 相关页面
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFormElement
    26. HTMLFrameSetElement
    27. HTMLHRElement
    28. HTMLHeadElement
    29. HTMLHeadingElement
    30. HTMLHtmlElement
    31. HTMLIFrameElement
    32. HTMLImageElement
    33. HTMLInputElement
    34. HTMLIsIndexElement
    35. HTMLKeygenElement
    36. HTMLLIElement
    37. HTMLLabelElement
    38. HTMLLegendElement
    39. HTMLLinkElement
    40. HTMLMapElement
    41. HTMLMediaElement
    42. HTMLMetaElement
    43. HTMLMeterElement
    44. HTMLModElement
    45. HTMLOListElement
    46. HTMLObjectElement
    47. HTMLOptGroupElement
    48. HTMLOptionElement
    49. HTMLOptionsCollection
    50. HTMLOutputElement
    51. HTMLParagraphElement
    52. HTMLParamElement
    53. HTMLPictureElement
    54. HTMLPreElement
    55. HTMLProgressElement
    56. HTMLQuoteElement
    57. HTMLScriptElement
    58. HTMLSelectElement
    59. HTMLShadowElement
    60. HTMLSourceElement
    61. HTMLSpanElement
    62. HTMLStyleElement
    63. HTMLTableCaptionElement
    64. HTMLTableCellElement
    65. HTMLTableColElement
    66. HTMLTableDataCellElement
    67. HTMLTableElement
    68. HTMLTableHeaderCellElement
    69. HTMLTableRowElement
    70. HTMLTableSectionElement
    71. HTMLTemplateElement
    72. HTMLTextAreaElement
    73. HTMLTimeElement
    74. HTMLTitleElement
    75. HTMLTrackElement
    76. HTMLUListElement
    77. HTMLUnknownElement
    78. HTMLVideoElement
    79. HashChangeEvent
    80. 历史
    81. ImageData
    82. 定位
    83. MessageChannel
    84. MessageEvent
    85. MessagePort
    86. Navigator
    87. NavigatorGeolocation
    88. NavigatorID
    89. NavigatorLanguage
    90. NavigatorOnLine
    91. NavigatorPlugins
    92. PageTransitionEvent
    93. Plugin
    94. PluginArray
    95. PopStateEvent
    96. PortCollection
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1