How to use try with multiple catch blocks exception handling in Groovy

1 Answer

0 votes
try {
        def arr = new int[5]
        arr[12] = 848
} catch(ArrayIndexOutOfBoundsException ex) {
        println "Exception: ${ex}"
} catch(Exception ex) {
        println "Exception: ${ex}"
}
         
println "After try catch catch"
 
 
 
/*
run:
 
Exception: java.lang.ArrayIndexOutOfBoundsException: Index 12 out of bounds for length 5
After try catch
 
*/

 



answered Oct 6, 2020 by avibootz

Related questions

1 answer 404 views
1 answer 279 views
1 answer 194 views
1 answer 284 views
284 views asked Mar 7, 2017 by avibootz
...