Scala Exceptions + try catch finally
Example:
1
try
2
{
3
// Dividing by zero
4
val result = 11/0
5
}
6
7
// Catch clause
8
catch
9
{
10
// Case statement
11
case x: ArithmeticException =>
12
{
13
14
// Display this if exception is found
15
println("Exception: A number is not divisible by zero.")
16
}
17
}
18
finally
19
{
20
println("This is how try catch finally works")
21
}
22
23
/*
24
Exception: A number is not divisible by zero.
25
This is how try catch finally works
26
*/
27
​
28
​
Copied!
Last modified 1yr ago
Copy link