关于try/catch用法的疑惑!等高手!!(88分)
我写了方法如下:它的返回类型是GX_PH_Measure 但是我把其中的else {
throw new SQLException (
"error.removed.Test");
}
这句去掉 就会提示这个方法需要一个 GX_PH_Measure类型的返回值!不知道为什么!抛出的这个异常和整个try/catch有什么关系呢!谢谢!
public GX_PH_Measure findSQL_formain(String sql,int ipage,HttpServletRequest request)
{
PreparedStatement ps = null;
ResultSet rs = null;
GX_PH_Measure m_Test=new GX_PH_Measure();
try {
if (con.isClosed()) {
throw new IllegalStateException("error.unexpected");
}
con.setAutoCommit(true);
ps = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = ps.executeQuery();
if (rs.next()) {
m_Test= new GX_PH_Measure();
m_Test.setModel_number(rs.getString(2));
return m_Test;
}else {
throw new SQLException (
"error.removed.Test");
}
//</find>
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("error.unexpected");
} finally {
try {
if (rs != null)
rs.close();
if (ps != null)
ps.close();
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("error.unexpected");
}
}
}