Scala study notes -05- exception handling

  • Scala does not support java "abnormalities", all exceptions are treated as "unchecked exception" (ie runtime exception)
  • Scala exception caught by a try - catch statement
import java.io.FileReader
import java.io.FileNotFoundException
import java.io.IOException

try{
	val f = new FileReader("./test.txt")
} catch {
	case ex: FileNotFoundException => println("File not found")
	case ex: IOException => println("IOException")
} finally {
	f.close()
}

 

[Imperfect, to be supplemented]

Guess you like

Origin www.cnblogs.com/wooluwalker/p/12301091.html