How to catch exception and use try catch in Scala

1 Answer

0 votes
import java.io.FileReader
import java.io.FileNotFoundException
import java.io.IOException

object Demo {
   def main(args: Array[String]): Unit = {
      try {
         val f = new FileReader("test.txt")
      } catch {
         case ex: FileNotFoundException => {
            println("FileNotFoundException")
         }
         case ex: IOException => {
            println("IOException")
         }
      }
   }
}




/*
run:

FileNotFoundException

*/

 



answered Jun 4, 2021 by avibootz

Related questions

1 answer 225 views
225 views asked Jun 4, 2021 by avibootz
2 answers 287 views
1 answer 395 views
...