Checked Exceptions
import java.io.*; public class IOExceptionExample { public static void main(String[] args) { try { FileReader reader = new FileReader("example.txt"); // Perform file operations here } catch (IOException e) { e.printStackTrace(); } } }import java.io.*; public class FileNotFoundExceptionExample { public static void main(String[] args) { try { FileInputStream fileInputStream = new FileInputStream("nonexistent.txt"); } catch (FileNotFoundException e) { e.printStackTrace(); } } }public class ClassNotFoundExceptionExample { public static void main(String[] args) { try { Class.forName("NonExistentClass"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }import java.sql.*; public class SQLExceptionExample { public static void main(String[] args) { try { Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/nonexistentdb", "user", "password"); } catch (SQLException e) { e.printStackTrace(); } } }import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class ParseExceptionExample { public static void main(String[] args) { try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse("invalid-date"); } catch (ParseException e) { e.printStackTrace(); } } }
Last updated