java multiple catch code example
Example 1: java catch multiple exceptions
catch(IOException | SQLException ex){
logger.error(ex);
throw new MyException(ex.getMessage());
}
Example 2: is try and catch block catching only one exception
class Main {
public static void main(String[] args) {
try {
int array[] = new int[10];
array[10] = 30 / 0;
} catch (ArithmeticException e) {
System.out.println(e.getMessage());
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
}
}
}