标签:
检查型异常checked
public class AhDataBaseException extends Exception {
public AhDataBaseException(String message, Throwable cause) {
super(message,cause);
}
}
public class ConnectionManager {
public ResultSet execSelectSQL(String sql) throws AhDataBaseException{
try {
conn.setAutoCommit(true);
PreparedStatement st = getPreparedStatement(sql);
return st.executeQuery();
} catch (SQLException e) {
//e.printStackTrace();
throw new AhDataBaseException(sql,e);
}
}
}
<%
ConnectionManager smgr = new ConnectionManager();
String sql = "select MMSId from a_shipinfoais";
try{
ResultSet rs = smgr.execSelectSQL(sql);
int i = 0;
while(rs.next()){
i++;
out.println(rs.getString("MMSI"));
if (i>100) break;
}
}catch(AhDataBaseException e){
e.printStackTrace();
}
%>
非检查型异常non-checked:
public class AhCheckDataException extends RuntimeException {
public AhCheckDataException (String message){
super(message);
}
}
public class Peoples{
private int num = 0; //min = 0 ;max = 100
public setnum(int value){
if ((value<0)||(value>100)){
throw new AhCheckDataException("Out of bound. sun = "+value);
}
}
};
public class test{
public static void main(String[] argc){
Peoples pps = new Peoples();
pps.setnum(101);
}
};

标签:
原文地址:http://www.cnblogs.com/melody-emma/p/4975629.html