1.3.3 improved Exception Handling and 1.3.3 improved Exception Handling
Demo:
Import java. io. IOException; import java.net. serverSocket; public class CoinTryCatch {public static void main (String [] args) {/** this Demo needs to be optimized to be more reasonable and comprehensive **/try {// java. lang. arithmeticException:/by zero System. out. println (5/0); // IO ServerSocket ss = new ServerSocket (8888); ss. close (); // OutOf String [] sarr = new String [] {}; System. out. println (sarr [0]);/** | **/} catch (IOException | ArrayIndexOut OfBoundsException e) {System. out. println ("caught IO or OutOf exception! ");/** Final Java 7 Exception re-throwing -- the final keyword is not required **/} catch (final Exception e) {e. printStackTrace ();}}}
Ran As Java Application:
Java. lang. ArithmeticException:/by zero at cointest. CoinTryCatch. main (CoinTryCatch. java: 13)