Convert checked exception into unchecked exception
800529Sep 25 2010 — edited Sep 25 2010Hi friends
I am little confused, When deciding on checked exceptions vs. unchecked exceptions. I went through the net. they are telling that
Use checked exceptions when the client code can take some useful recovery action based on information in exception. Use unchecked exception when client code cannot do anything.
Here what is the client code. which is the best way is checked exception good or is unchecked exception good or shall i simply tell catch(Exception e){...} or do i have to tell the particular exception like catch(SQLException) {..} instead of mentioning catch(excetpion){....}. I am so much confused...
Could you please tell me how to convert this code from checked exception into unchecked exception.
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root", "sheik");
if(!con.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");
PreparedStatement ps = con.prepareStatement("DELETE FROM EMPLOYEE WHERE ID=?");
ps.setInt(1, 3);
System.out.println(ps.executeUpdate());
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {
System.out.println(e);
}
}
Thanks and Regards
Sherin Pooja