当前位置: 代码迷 >> J2SE >> method的exception与方法内exception的区别解决办法
  详细解决方案

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

热度:123   发布时间:2016-04-24 01:44:00.0
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 是说方法可能抛出异常
  相关解决方案