Failure and exceptions in Scala

At first, let's define what we mean by failures in general (source: https://tersesystems.com/2012/12/27/error-handling-in-scala/):

  • Unexpected internal failure: The operation fails as the result of an unfulfilled expectation, such as a null pointer reference, violated assertions, or simply bad state
  • Expected internal failure: The operation fails deliberately as a result of internal state, that is, a blacklist or circuit breaker
  • Expected external failure: The operation fails because it is told to process some raw input, and will fail if the raw input cannot be processed
  • Unexpected external failure: The operation fails because a resource that the system depends on is not there: there's a loose file handle, the database connection fails, or the network is down

Unfortunately, there are no concrete ways of stopping failures unless the failures are due to some manageable exceptions. On the other hand, Scala makes checked versus unchecked very simple: it doesn't have checked exceptions. All exceptions are unchecked in Scala, even SQLException and IOException, and so on. Now let's see how to handle such exceptions at least.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.180.81