一个java类的问题
public class ProfitReport {
private HttpServletRequest request=null;
private String begin="";
private String end="";
/**
* <p>Construtor</p>
* @param request 请求对象
* <p>Create Time: 2007-08-04</p>
*/
public ProfitReport(HttpServletRequest request,String Begin ,String End) {
this.request = request;
this.begin=Begin;
this.end=End;
}
EspSys espsys=new EspSys();
YanZheng yz = new YanZheng(request);
ContractMethod cm = new ContractMethod(request);
private String dbname=espsys.getDBName(request);//获取数据库名称
private HashMap ProHashMap=getRecvSumTable(begin, end);现在这里报错,说Unhandled exception type Exception 怎么解决啊
public HashMap getRecvSumTable(String Begin,String End )throws Exception
{
HashMap hm = new HashMap();
Vector vtRecvSum = new Vector();//--收货记录
Vector vtBuyForm = new Vector();//--购进单记录
Vector vtPayForm = new Vector();//--调拨单记录
//-收货记录
// 0 1 2 3 4 5 6 7 8 9 10
String sqlStr=" select id ,sendid,buyid,cityid,saltid,accdton,frecvton,transformton,bagtype_id,spec_id,bagmaterial_id"+
" from syrecvsum where (proisbuy=1 or issend=1) and status=0 ";
//--购进单记录
// 0 1 2 3 4 5 6
String sqlStr1=" select id,sendid,mixedfee,recvids,cityid,saltnames,createdate from sybuyform where createdate>='"+Begin+" 00:00:00'"+
" and createdate<='"+End+" 23:59:59'";
//--调拨单记录
// 0 1 2 3 4 5 6
String sqlStr2=" select id,buyid,fatherid,sumsdate,recvids,suppliers,saltnames from syrecvsums where sumsdate>='"+Begin+" 00:00:00'"+
" and sumsdate<='"+End+" 23:59:59'";
try
{
vtRecvSum=BasePeer.executeQuery(sqlStr);
vtBuyForm=BasePeer.executeQuery(sqlStr1);
vtPayForm=BasePeer.executeQuery(sqlStr2);
}
catch(Exception ex)
{
ex.getMessage();
}
hm.put("RecvSum", vtRecvSum);
hm.put("BuyForm", vtBuyForm);
hm.put("PayForm", vtPayForm);
return hm;
}
』
------解决方案--------------------有潜在的exception你必须要处理 把该语句放到try块中 并做异常处理
------解决方案--------------------好像是你的getRecvSumTable方法签名中声明了Exception 异常,你在ProfitReport 类中用getRecvSumTable时得作出处理
换成下面的试试
try{
private HashMap ProHashMap=getRecvSumTable(begin, end);
}catch(Exception e){
//do something;
}
------解决方案--------------------
private HashMap ProHashMap=getRecvSumTable(begin, end);现在这里报错,说Unhandled exception type Exception 怎么解决啊
这句话说明
getRecvSumTable(begin, end); 在使用的时候会发生异常。 而你没有捕获这个异常。所以才会有如此的提示
你可以
Java code
private HashMap ProHashMap=null;
public ProfitReport(HttpServletRequest request,String Begin ,String End) {
this.request = request;
this.begin=Begin;
this.end=End;
try
{
ProHashMap =getRecvSumTable(begin, end);
}catch(Exception e)
{
.....
}
}