奇怪的问题:Exception is not compatible with throws clause !会者很easy!

mint 2007-07-12 11:48:24
public class LoadMaps implements ContentMaps {
....
public MAP getUserMap(int localID) throws Exception{
// TODO Auto-generated method stub
MAP map=new MAP();
...
Oracle newConnection=new Oracle();
Connection conn= newConnection.newConnection();
try{

Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

String sql="select * from MAP_PIN where LocalID='"+localID+"'";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
... };
rs.close();
stmt.close();
}

finally{
if(conn!=null){conn.close();}
}


return map;
}
}
结果提示:
Exception Exception is not compatible with throws clause in ContentMaps.getUserMap(int)

不明白为什么,请高手指点!
...全文
2724 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
qbquan 2007-07-13
  • 打赏
  • 举报
回复
没写catch
jihanzhong 2007-07-13
  • 打赏
  • 举报
回复
public MAP getUserMap(int localID) throws Exception{


查查ContentMaps里有没有throws Exception
rypgood 2007-07-13
  • 打赏
  • 举报
回复
我这边不能调试你的程序,我记得try-finally这样结合是可以的,可以没有catch,但是没有finally的话就必须有一个以上catch.
根据提示应该抛出的并不是Exception或者其子类,你改下你的抛出范围,改成如下:
public MAP getUserMap(int localID)throws Throwable
这样应该就不会错了.我不能调试你的程序,还得麻烦楼主自己调试了.
xiaxinhuo 2007-07-13
  • 打赏
  • 举报
回复
try{}catch(){}是一个整体有try的话一定要有catch.
sky_810613 2007-07-13
  • 打赏
  • 举报
回复
是不是你的接口ContentMaps.getUserMap(int) 在声明的时候抛出的是Exception的子类呢,我记得在实现接口时,子类抛出是异常应该是和父类的相同或是比父类的范围小才对的
jihanzhong 2007-07-13
  • 打赏
  • 举报
回复
呵呵,考你呢
zhuokai 2007-07-13
  • 打赏
  • 举报
回复
----------------------------------
try{
.............
}
finally{
if(conn!=null){conn.close();}
}
----------------------------------

不知道樓主想幹嘛,把catch丟哪去了.................
joejoe1991 2007-07-13
  • 打赏
  • 举报
回复
我记得catch 和 finally 写上其中一个就可以了
cccp21 2007-07-13
  • 打赏
  • 举报
回复
try-finally是可以的
但是这里大概是因为try里面有抛出异常的语句,所以编译器非要你catch
cccp21 2007-07-13
  • 打赏
  • 举报
回复
try-finally是可以的
weihthchk 2007-07-13
  • 打赏
  • 举报
回复
听一星专家的。
throws子句的Exception和接口中声明的不一致,比较大的可能是ContentMaps的getUserMap(int)方法声明时规定了throws Throwable。

62,633

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧