Q:
何故,例外はmap<EventListener>を用いないのか.
例外機構が局所的なEventListeningであることは論を俟たない.
A:
例外機構は「後続の処理を行わずにlistenerをkickさせる」.
/**
* When toss generate an Exception then throw it, smash won't be kicked.
*/
const doItStandard = () => {
try {
toss();
smash();
} catch (e) {
console.log(e);
}
}
/**
* When toss generate CustomEvent: {type: 'exception arose'} then dispatch it to hoge, smash will be kicked.
* [toss, smash] could generate CustomEvent: {type: 'exception arose'}.
* [toss, smash] could dispatch CustomEvent: {type: 'exception arose'} to hoge
*/
const doItExtra = () => {
hoge.addEventListner('exception arose', (e) => { console.log(e); });
toss();
smash();
}