1. Catching exceptions gives us the opportunity to recover the program. This is the benefit of exceptional existence.
Exceptions also make the program less readable, such as an exception that introduces a context-dependent variable substitution, and the way in which an exception might occur is not type-safe (that is, it does not run as it is committed to its interface)
The main idea of functional exception handling is to not throw an exception, but instead to return a value indicating that the exception has occurred. Just like the return code in the C language.
2. Look at a "partial function": a function that has certain assumptions about the value of a parameter
def mean (xs:seq[double]): Double = if (xs.isempty) throw new ArithmeticException ("Mean of empty list") Else XS . sum/xs.length
3. Compromise solution: To be able to easily add exception handling logic, for the repair program, but also to be type-safe, to ensure the function of the function
Sealed trait Option[+a] case class Some[+a] (GET:A) extends Option[a] Case Object None extends option[nothing] def mean (Xs:seq[double]): Double = if (xs.isempty) None else Some (xs.sum/xs.length)
Play Scala 6 Function-type exception handling