我有一个实现以下接口的基类,在其上声明的方法抛出基本异常类型Exception
。
有许多扩展基类的具体类,我不想在所有这些类中添加一个try-catch
块。有throws
没有不添加的方法来处理try-catch
?
界面
public interface IReportFactory {
public Object GetDataFromDB(Connection conn,HashMap<String,String> map) throws Exception;
public Object GetJSONString(HashMap<String,String> map) throws Exception;
}
基类
public abstract class BaseReport implements IReportFactory{
public Connection conn;
public String acctId = FactoryReport.getAcctId();
------ I WANT TO CATCH EXCEPTION HERE ------
------ WHICH ACCURS IN OTHER CLASSES WHICH EXTENDS FROM THIS CLASSES -----
}
具体类的例子(有30个)
public class GeneralRevenue extends BaseReport {
private final Logger logger = Logger.getLogger(GeneralRevenue.class);
public GeneralRevenue(Connection _conn) {
this.conn = _conn;
}
@Override
public Object GetJSONString(HashMap<String,String> params) throws Exception {
//codes
return jObj.toString();
}
@Override
public Object GetDataFromDB(Connection conn,HashMap params) throws Exception {
//codes
return RevenueList;
}
}