Scala Exceptions + try catch finally

Example:

try
    { 
        // Dividing by zero 
        val result = 11/0
    } 
      
    // Catch clause 
    catch
    {  
            // Case statement 
            case x: ArithmeticException => 
            {  
          
            // Display this if exception is found 
            println("Exception: A number is not divisible by zero.") 
        } 
    }
    finally
    {
        println("This is how try catch finally works")
    }
    
    /*
    Exception: A number is not divisible by zero.
    This is how try catch finally works
    */

Last updated