LoginSignup
0
0

More than 5 years have passed since last update.

ExceptionのcatchでPromiseとtry-catchを比較する

Posted at

ExceptioncatchPromiseを使った場合とtry-catchを使った場合の比較を雑にしました。

検証コード

% node
> console.time("promise"); i = 10000; while(i-- > 0){ new Promise((resolve, reject)=>{ throw new Error(); }).catch((err)=>{1}) } console.timeEnd("promise");
1: 139.171ms
undefined
> console.time("try"); i = 10000; while(i-- > 0){ try{ throw new Error(); }catch(err){ 1; } } console.timeEnd("try");
1: 56.821ms
undefined
> 

うん、使えるところなら try-catch 使おう。

0
0
1

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