1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【JavaScript】エラーの種類で処理を分ける方法

Last updated at Posted at 2023-11-13

以下のようにinstanceofを使用することでエラーの種類によって処理を分けることができます。

try {
  throw new TypeError()
} catch (err) {
  if (err instanceof TypeError) {
    // TypeErrorの場合の処理
  } else {
    console.log('その他')
  }
}
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?