blob: 75eccd8a776fef5271ba8e4f17ed9aceff463876 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
---
title: 'Window: rejectionhandled イベント'
slug: Web/API/Window/rejectionhandled_event
tags:
- API
- Event
- HTML DOM
- JavaScript
- Promise
- Promises
- Reference
- Window
- Worker
- global
- onrejectionhandled
- rejectionhandled
- イベント
translation_of: Web/API/Window/rejectionhandled_event
---
<div>{{APIRef("HTML DOM")}}</div>
<p><span class="seoSummary"><strong><code>rejectionhandled</code></strong> イベントは、 JavaScript の {{jsxref("Promise")}} が拒否されたものの、その後で Promise の拒否が処理された場合にスクリプトのグローバルスコープ (ふつうは {{domxref("window")}} だが {{domxref("Worker")}} の場合もある) に送られます。</span>これは、 Promise が拒否されたが拒否の手助けがないときに送信される {{domxref("Window.unhandledrejection_event", "unhandledrejection")}} イベントと並行して、デバッグや一般的なアプリケーションの回復に使用できます。</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">バブリング</th>
<td>なし</td>
</tr>
<tr>
<th scope="row">キャンセル可能</th>
<td>いいえ</td>
</tr>
<tr>
<th scope="row">インターフェイス</th>
<td>{{domxref("PromiseRejectionEvent")}}</td>
</tr>
<tr>
<th scope="row">イベントハンドラープロパティ</th>
<td>{{domxref("WindowEventHandlers.onrejectionhandled", "onrejectionhandled")}}</td>
</tr>
</tbody>
</table>
<h2 id="Example" name="Example">例</h2>
<p><code>rejectionhandled</code> イベントを使用して、拒否された Promise を、拒否された理由を添えてコンソールに出力することができます。</p>
<pre class="brush: js">window.addEventListener("rejectionhandled", event => {
console.log("Promise rejected; reason: " + event.reason);
}, false);
</pre>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
<th scope="col">状態</th>
<th scope="col">備考</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('HTML WHATWG', 'webappapis.html#unhandled-promise-rejections', 'rejectionhandled')}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td>初回定義</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの対応</h2>
<p>{{Compat("api.Window.rejectionhandled_event")}}</p>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{SectionOnPage("/ja/docs/Web/JavaScript/Guide/Using_promises", "Promise rejection events")}}</li>
<li>{{domxref("PromiseRejectionEvent")}}</li>
<li>{{jsxref("Promise")}}</li>
<li>{{domxref("Window/unhandledrejection_event", "unhandledrejection")}}</li>
</ul>
|