Re: [問題] 檢查錯誤
※ 引述《ccricky@kkcity.com.tw ( )》之銘言:
: ※ 引述《blueace.bbs@ptt.cc (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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):