Java关键字finally_动力节点Java学院整理
2017-10-11 16:12
741 查看
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中final,finally,finalize三个关键字的区别_动力节点Java学院整理
- Java关键字finally_动力节点Java学院整理
- Java中的super关键字_动力节点Java学院整理
- 深入理解Java中的final关键字_动力节点Java学院整理
- Java中的关键字_动力节点Java学院整理
- Java中的super关键字_动力节点Java学院整理
- Java Runtime类详解_动力节点Java学院整理
- Java中的HashSet详解和使用示例_动力节点Java学院整理
- C#,Java,C++中的finally关键字
- Java递归读取文件例子_动力节点Java学院整理
- Java 异步编程实践_动力节点Java学院整理
- Java中final关键字整理
- Java class文件格式之特殊字符串_动力节点Java学院整理
- Java中的finally关键字
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗
- Java二进制操作(动力节点Java学院整理)
- Java数据结构之链表_动力节点Java学院整理
- java(instanceof操作符、对象类型转换 、final 关键字、final,finally,finalize的区别、static关键字,修饰符 )
- java中final,finally,finalize三个关键字的区别
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意思?