Java examples for Language Basics:try catch finally
Catching Multiple Exceptions with a vertical bar operator | for each of the exceptions
import java.io.FileInputStream; import java.io.IOException; public class Main { public static void main(String[] args) { try {//w w w .jav a 2 s. c om Class<?> stringClass = Class.forName("java.lang.String"); FileInputStream in = new FileInputStream("myFile.log"); // Can throw // IOException in.read(); } catch (IOException | ClassNotFoundException e) { System.out.println("An exception of type " + e.getClass() + " was thrown! " + e); } } }