Simple exception chaining problem
The problem is 'throw new ClientException(e.getMessage());' the error message kept stating to be in try/catch but it's already in try bracklet. I tried placing the exception in other bracklet but it defeats the purpose of showing the exception in this specific bracklet. I'm not sure what's the solution of this, I got the two solutions in netbeans - make a new try/catch or extending the exception. I looked at the book, I don't see this class extending anything.
import java.sql.Connection;
import java.sql.SQLException;
publicclass ClientBO{
private Connection con;
/** Creates a new instance of ClientBO */
public ClientBO(){
con = TomcatDAOFactory.createConnection();
}
publicvoid addSheet(SheetsForm sheetsform){
Connection con =null;
try{
TomcatClientDAO tomcatclientdao =new TomcatClientDAO(con);
tomcatclientdao.createTest(sheetsform);
con.commit();
}catch (Exception e){
try{
if (con !=null){
con.rollback();
thrownew ClientException(e.getMessage());
}
}catch (SQLException sqle){
e.printStackTrace();
thrownew RuntimeException("error.unexpected");
}
}finally{
try{
if (con !=null){
con.close();
}
}catch (SQLException sqle){
sqle.printStackTrace();
thrownew RuntimeException("error.unexpected");
}
}
}
}

