异常问题请教

iamlovelx 2004-08-23 09:20:56
mport java.io.*;
public class Helloworld {
public static void main(String[] args)throws IOException{
System.out.println("请输入字符串:");
int s=System.in.read( );
System.out.println("你所输入的字符串为:"+s);


}
}
为什么已经申明了throws IOException,而在函数内部没有throw IOException,然而在有的函数throws后在函数内部却又throw了。有throw跟没有throw究竟有什么区别??
...全文
75 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
draco2002 2004-08-23
  • 打赏
  • 举报
回复
你可以看一下我回复的帖子:

http://community.csdn.net/Expert/topic/3288/3288113.xml?temp=.2264215
dragon525 2004-08-23
  • 打赏
  • 举报
回复
throw只是把异常传给下一级的调用函数,来catch异常。。。。。。。。。

public void aaa() throws exception{

}

在调用aaa方法的函数中就可以捕获其抛出的异常,进行相应的处理。。

public void bbb(){
try{
aaa();
}
catch(excption e){}//-------->可以准确的捕获到aaa函数所抛出的异常。。。。

}

62,623

社区成员

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

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