Null, Validations and Exceptions

Null The billion Dollars Mistake

Validations First

Exceptions Best Practices

  • Item 49 — Check Parameters for Validity
  • Public/protected methods use @throws on Javadoc
  • Objects.requireNonNull
  • @Nullable when the parameter can be null
  • Non-public method(private) can check parameters with assertions (assert)
  • Item 69: Use Exception only for exceptional conditions (Dont use for ordinary control flow)
  • Item 72: Favor the use of Standard Exceptions
  • Item 73: Throw Exceptions appropriate to the abstraction (High level would catch lower level)
  • Item 74: Document all exception throw by each method (/** Javadoc @throws */
  • Item 75: Include failure capture information in the detail message
  • Item 76: Strive for failure atomicity (Generally Exception should leave the object how it was before the exception)
  • Item 77: Don’t ignore Exceptions

Functional Programing and Modern Ways to handle errors

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Diego Pacheco

Diego Pacheco

424 Followers

Brazilian, Software Architect, SWE(Java, Scala, Rust, Go) SOA & DevOps expert, Author. Working with EKS/K8S. diegopacheco.github.io (Opinions on my own)