首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

method的exception与方法内exception的区别解决办法

2012-03-27 
method的exception与方法内exception的区别public void print(String phrase, int max){if (phrase nul

method的exception与方法内exception的区别
public void print(String phrase, int max){
if (phrase == null || max < 0){
throw new IllegalArgumentException("String is null, or max is smaller than 0");
}
}
上面的这个是一个普通的throw new IllegalArgumentException
==========================================================================

  public static void main(String[] args) throws FileNotFoundException
这个是定义在method这一行的。
=========================================================================

请问这两者有什么区别?定义method这一行的Exception看起来没有什么实质性作用。

[解决办法]
异常机制及throw与throws的区别
[解决办法]
简单说
throw 是你自己抛出异常
throws 是说方法可能抛出异常

热点排行
Bad Request.