--- title: WindowEventHandlers.onunhandledrejection slug: Web/API/WindowEventHandlers/onunhandledrejection tags: - API - Event Handler - HTML DOM - Promises - Property - Reference - WindowEventHandlers - events - onunhandledrejection translation_of: Web/API/WindowEventHandlers/onunhandledrejection ---
{{domxref("WindowEventHandlers")}} ミックスインの onunhandledrejection プロパティは、{{event("unhandledrejection")}} イベントを処理するための {{event("Event_handlers", "event handler")}} です。 このイベントは、処理されなかった {{jsxref("Promise")}} 拒否に対して発生します。
window.onunhandledrejection = function;
function は、ウィンドウが unhandledrejection イベントを受け取ったときに呼び出す {{event("Event_handlers", "event handler")}} または関数です。 イベントハンドラは、{{domxref("PromiseRejectionEvent")}} を入力パラメーターとして受け取ります。
この例では、処理されなかった拒否の reason 値を単にコンソールに記録します。
window.onunhandledrejection = function(e) {
console.log(e.reason);
}
| 仕様 | 状態 | コメント |
|---|---|---|
| {{SpecName('HTML WHATWG', 'webappapis.html#handler-window-onunhandledrejection', 'onunhandledrejection')}} | {{Spec2('HTML WHATWG')}} | 初期定義 |
{{Compat("api.WindowEventHandlers.onunhandledrejection")}}