不起作用(編譯錯誤:缺少return語句)爲什麼一個嘗試catch裏面工作return語句 '拋出'
public SqlMapClientTemplate getSqlTempl() throws UivException, SQLException{
try {
SqlMapClient scl = (SqlMapClient) ApplicationInitializer.getApplicationContext().getBean("MySqlMapClient");
DataSource dsc = (DataSource) ServiceLocator.getInstance().getDataSource(PIH_EIV_ORCL);
return new SqlMapClientTemplate (dsc, scl);
}
catch (NamingException ne)
{
log.error(ne.getMessage(), ne);
}
}
作品:
public SqlMapClientTemplate getSqlTempl() throws UivException, SQLException{
try {
SqlMapClient scl = (SqlMapClient) ApplicationInitializer.getApplicationContext().getBean("MySqlMapClient");
DataSource dsc = (DataSource) ServiceLocator.getInstance().getDataSource(PIH_EIV_ORCL);
return new SqlMapClientTemplate (dsc, scl);
}
catch (NamingException ne)
{
log.error(ne.getMessage(), ne);
throw new SQLException("Unable to get database connection: " + ne.getMessage());
}
}
爲什麼呢?
你是什麼意思「不起作用」?第一種情況會發生什麼? – noctonura 2009-11-06 02:56:22
我相信這很明顯。 :) – 2009-11-06 02:59:00
既然您期望第一個案例能夠奏效,那麼我不得不問,您預期這個方法會返回什麼結果? – 2009-11-06 04:19:52