import java.io.FileReader import java.io.FileNotFoundException import java.io.IOException object Demo { def main(args: Array[String]) { try { val f = new FileReader("input.txt") } catch { case ex: FileNotFoundException => println("Missing file exception") case ex: IOException => println("IO Exception") } finally { println("Exiting finally...") } println("End of the program ..."); } }
import java.io._ object Demo { def div(a : Int, b : Int) : Float = { if(b == 0) throw new IllegalArgumentException("x should be non-zero") return a.toFloat/b } def main(args: Array[String]) { try { println(div(1, 0)) } catch { case ex: IllegalArgumentException => println(ex) } println("End of the program ..."); } }