Try Catch
Introduction
public void testVoid(){
int[] arr = new int[3];
int i = arr[3];
}
// Output:java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
// CallStack ...
try {
// block of code to monitor for errors
// the code you think can raise an exception
}
catch (ExceptionType1 exOb) {
// exception handler for ExceptionType1
}
catch (ExceptionType2 exOb) {
// exception handler for ExceptionType2
}
// optional
finally {
// block of code to be executed after try block ends
}Throw
Try-With-Resource
Last updated