try catchするときはなんでもcatchしてはいけない
before
public boolean tryHoge() { try { // 例外が起きそうな処理; HogeExceptionかFugaExceptionが想定される return true; } catch (Exception e) { return false; } return false; }
たとえばこのとき例外が起きそうな処理の中でNullPointerExceptionがあっても知らずにcatchしてしまう。
after
public boolean tryHoge() { try { // 例外が起きそうな処理; HogeExceptionかFugaExceptionが想定される return true; } catch (HogeException | FugaException e) { return false; } return false; }
予想してない例外までcatchしてしまわないように、catchするものはなるべく少なくする。