Scala: How do I know that there were unhandled exceptions before starting the program?

this is a test program:

object Test {

    def main(args: Array[String]): Unit = {
        // there is an unhandled exception in here, I expect program can remind me, and I can handled it before running.
        myException()  
    }

    def myException: Unit ={
        throw new Exception
    }
}

In Java, when I call a method with an exceptional exception, an error will occur in the program and will tell you add throws declarationor surround with try/catch.

How do I know if a program has unhandled exceptions before running in Scala ?

+4
source share
2 answers

Scala has a slightly different philosophy regarding Exceptions.

, , - , , " ". , , , FP .

Either Option / "", . (, @Tawkir, )

, Java-, Exceptions , . , Try, recover recoverWith , , .

, scala @throws, (), , scala, Java-, .

+7

JVM. Java, , RuntimeException . Scala , , .

+1

Source: https://habr.com/ru/post/1671565/


All Articles