LoginSignup
0
0

More than 1 year has passed since last update.

Why are Exception(s) excepted?

Last updated at Posted at 2022-09-07

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();
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0