作者adrianshum (Alien)
看板java
标题Re: [问题] 检查错误
时间Thu Jun 21 11:50:26 2007
※ 引述《[email protected] ( )》之铭言:
: ※ 引述《[email protected] (never)》之铭言:
: > public class Test20{
: > public static void main(String[] args){
: > try{
: > m();
: > n();
: > }
: > catch(Exception ex){
: > System.out.println("捉到例外:"
: > +ex.getMessage());
: > }
: > }
: static void m()throws RuntimeException{ <===忘了加
RuntimeException 是 unchecked exception.
不需要 declare throws.
所以不加这句也能 compile
: > throw new RuntimeException("例外一");
: > }
: static void n()throws Exception{ <===忘了加
: > throw new Exception("例外二");
: > }
: > }
: > 不好意思请问一下,为什麽我执行完後错的地方是throw new Exception("例外二");
: > 这行呢?不太懂,有大大可以帮我解答一下吗?感谢
: 改过後,执行结果为"捉到例外:例外一",没加之前,不能编译才对
alien
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 202.22.246.26