Scala program to demonstrate the throws keyword
// Scala program to demonstrate the
// "throws" keyword
object Sample {
@throws(classOf[ArithmeticException])
def divide(num1: Int, num2: Int): Int = {
return (num2 / num1);
}
// Main method
def main(args: Array[String]) {
var num1: Int = 2;
var num2: Int = 10;
var res: Int = 0;
try {
res = divide(num1, num2);
printf("Result: %d\n", res);
} catch {
case e: ArithmeticException => println(e);
} finally {
println("Finally block executed")
}
}
}
output
Result: 5
Finally block executed
Table of Contents