1.如果執行了try塊沒有異常,則繼續運行finally塊中的語句,即使try塊通過return,break,或者continue于最后的語句退出,finally中的語句也是會執行的。
總結:
不管是否出現異常,finally子句總是在塊完成之前執行。
代碼:
import java.util.Scanner;public class DivideByTwo{public static void main(String args[]){Scanner in=new Scanner(System.in);int x;System.out.println("please enter integer:");try{String oneline=in.nextLine();x=Integer.ParseInt(oneLine);System.out.println("half of x is"+(x/2));}catch(NumberFormatException e){System.out.println(e);} finally{System.out.println("hello world!");}}}
以上所述是小編給大家介紹的Java關鍵字finally_動力節點Java學院整理,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答