LoginSignup
0
1

More than 1 year has passed since last update.

検査例外、非検査例外

Posted at

検査例外、非検査例外

非検査例外(RuntimeException)
try-catchでエラーを捕捉しなくてもよい。
というより、むしろすべきでない。
コードの書き方で起こるもの。

検査例外(Exception配下のRuntimeException以外)
これは、必ずどこかでtry-catchしなくてはならない。
コードで防ぎようのないエラーだから。(正しくコードを書いていても起きるときには起きる。目的のファイルがない、SQLの接続がうまくいかなかったなど)

それが発生するメソッド内でtry-catchしなくてもthrowsで、呼び出し元でエラーハンドリングすることができる。

0
1
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
1