Last active
March 16, 2017 05:24
-
-
Save matsu-chara/cc4e62defc741f2c6de92ae50be62963 to your computer and use it in GitHub Desktop.
危険例のようにabstract class宣言時やextends時にcauseのデフォルト引数でnullを指定するとcauseを渡し忘れる事故が発生するので避けた方が好ましい。(causeを渡し忘れているためスタックトレースが追跡できない状態になっているが、コンパイルは通るし相当気づきにくいので本番でエラーログみようとして初めて情報がないことに気づく・・・という事故)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class DomainException(message: String, cause: Throwable) extends RuntimeException(message, cause) | |
sealed abstract class FooDomainException(message: String, cause: Throwable) extends DomainException(message, cause) | |
// causeが必ず存在するような例外 | |
case class BarDomainException(message: String, cause: Throwable) extends FooDomainException(message, cause) | |
// causeがあったりなかったりするような例外 | |
case class BazDomainException(message: String, cause: Throwable = null) extends FooDomainException(message, cause) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ミス防止のために避けたほうがよい例1: abstract class宣言時にデフォルトでnullを渡す | |
sealed abstract class FooDomainException(message: String, cause: Throwable = null) extends DomainException(message, cause) | |
case class BarDomainException(message: String, cause: Throwable) extends FooDomainException(message) // cause渡し忘れ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ミス防止のために避けたほうがよい例2: extends時にnullを渡す | |
sealed abstract class FooDomainException(message: String, cause: Throwable) extends DomainException(message, cause) | |
case class BarDomainException(message: String, cause: Throwable) extends FooDomainException(message, null) // cause渡し忘れ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment