In the
Java programming language, the block is used often to catch
exceptions. All potentially dangerous code is placed inside the block and, if an exception occurred, is stopped, or caught. import java.io.File; import java.io.IOException; import java.util.Scanner; try { // Try to read the file "file.txt" Scanner sc = new Scanner(new File("file.txt")); while (sc.hasNextLine()) { System.out.println(sc.readLine()); } sc.close(); } catch (IOException e) { // The file could not be read System.err.println("The file could not be read. Stack trace:"); e.printStackTrace(); } == In C ==