Java exception types thrown as parent type

class Main {

public static void main(String[] args) {

 

class Rex extends RuntimeException {

public Rex(String message) {

super(message);

}

}

 

try {

try {

throw new Rex(“rex”);

} catch (RuntimeException e) {

throw e;

}

} catch (Rex ex) {

System.out.println(“Rex:” + ex.getMessage());

} catch (RuntimeException ex) {

System.out.println(“RuntimeException:” + ex.getMessage());

}

 

}

}

java version “1.8.0_31”

Java(TM) SE Runtime Environment (build 1.8.0_31-b13)

Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

 

Rex:rex