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.
add throws declaration
surround with try/catch
How do I know if a program has unhandled exceptions before running in Scala ?
Scala has a slightly different philosophy regarding Exceptions.
Exception
, , - , , " ". , , , FP .
Either Option / "", . (, @Tawkir, )
Either
Option
, Java-, Exceptions , . , Try, recover recoverWith , , .
Try
recover
recoverWith
, scala @throws, (), , scala, Java-, .
@throws
JVM. Java, , RuntimeException . Scala , , .
Source: https://habr.com/ru/post/1671565/More articles:git rebase origin/develop vs git rebase develop - gitUsing rank () in Spark SQL - javaHow can I detect edges in a document image and cut sections into separate images? - image-processingКак установить конфигурацию запуска/отладки в IntelliJ IDEA с помощью Jar файла? - javaHow to create XHR request in angular2? - httpundefined reference to a function pointer variable template template in clang, but not gcc - c ++How to determine if sentence-in-text sentence detection (Unity IBM Watson sdk) is complete? - unity3dAngular 2, checkbox two-way model binding, dom, not reflecting the checked status when manipulating state from a component - angularConfiguring an explicit Content-Type response in CouchDB - jsonReact shorthand for passing props - reactjsAll Articles