技术标签: Java-异常处理
情况1:try块中没有抛出异常try和finally块中都有return语句
执行结果:
i in try block is10
i in finally - from try or catch block is9
the method value is8
执行顺序:执行try块,执行到return语句时,先执行return的语句,--i,但是不返回到main 方法,执行finally块,遇到finally块中的return语句,执行--i,并将值返回到main方法,这里就不会再回去返回try块中计算得到的值
情况2:try块中没有抛出异常,仅try中有return语句
代码:
执行结果:
i in try block is--10
i in finally - from try or catch block is--9
i in finally block is--8
the method value is--9
顺序:try中执行完return的语句后,不返回,执行finally块,finally块执行结束后,返回到try块中,返回i在try块中最后的值
情况3:try块中抛出异常try,catch,finally中都有return语句
代码:
执行结果:
i in try block is--10
i in catch - form try block is--10
i in catch block is--9
i in finally - from try or catch block is--8
i in finally block is--7
the method value is--6
顺序,抛出异常后,执行catch块,在catch块的return的--i执行完后,并不直接返回而是执行finally,因finally中有return语句,所以,执行,返回结果6
情况4,catch中有return,finally中没有,同上,执行完finally语句后,依旧返回catch中的执行return语句后的值,而不是finally中修改的值
情况5:try和catch中都有异常,finally中无return语句
结果:
i in try block is--10
i in catch - form try block is--10
i in finally - from try or catch block is--10
i in finally block is--9
Exception in thread "main" Java.lang.ArithmeticException: / by zero
at exception.ExceptionTest0123.CatchException(ExceptionTest0123.java:29)
at exception.ExceptionTest0123.main(ExceptionTest0123.java:17)
执行顺序:在try块中出现异常,到catch中,执行到异常,到finally中执行,finally执行结束后判断发现异常,抛出
情况6:try,catch中都出现异常,在finally中有返回
运行结果:
i in try block is--10
i in catch - form try block is--10
i in finally - from try or catch block is--10
i in finally block is--9
the method value is--8
执行顺序:try块中出现异常到catch,catch中出现异常到finally,finally中执行到return语句返回,不检查异常
没有catch,只有try和finally时,执行顺序和上面的几种情况差不多,只是少了catch块的执行
Errorchiyukunpeng@chiyukunpeng: ~$ git clone --recursive https://github.com/mrnabati/CenterFusion.git正克隆到 'CenterFusion'...fatal: unable to access 'https://github.com/mrnabati/CenterFusion.git/': gnutls_handshake() failed: The TLS connection was non-pro_cv error (-110): the tls connection was non-properly terminated
使用框架:Spring3 MVC + dojo1.8前提:配置Spring MVC以JSON数据形式响应请求使用场景:dojo向Spring MVC发送ajax请求异常信息:org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlenc
一、错误java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilterjava.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet二、分析出现这个问题,是因为工程的jar包..._使用idea启动项目遇见classnotfoundexception
这篇文章整理了TCP和UDP的相同点和不同点,没有非常详细地对TCP和UDP进行讲解,是一些总结性内容。一、TCP和UDP的概念TCP(Transmission Control Protocol),传输控制协议。UDP(User Data Protocol),用户数据报协议。二、TCP和UDP的异同点1. TCP和UDP的相同点: TCP和UDP都是在网络层,都是传输层协议,都能都是保护网络_简述tcp和udp的异同之处
USE [TEST]GO/****** Object: StoredProcedure [dbo].[Make_Directory] Script Date: 2012/7/12 16:15:53 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO/*------------------------------------_sql server 使用命令创建文件夹
Golang 支持交叉编译,在一个平台上生成另一个平台的可执行程序,最近使用了一下,非常好用,这里备忘一下。 Windows 下编译Linux 64位可执行程序SET CGO_ENABLED=0SET GOOS=linux SET GOARCH=amd64go build main.goGOOS:目标平台的操作系统(darwin、freebsd、linux、windows...
递归与分治題目內容:求n个元素中的最大元素值,要求用递归与分治策略解决。输入第1行:元素个数n第2行:n个元素的值输出:n个元素中的最大元素值实例:输入:8 //元素个数10 3 9 20 4 83 24 65 //8个具体的元素值输出:83 //最大元素值输入输出说明:输入第1行:元素个数n第2行:n个元素的值输出:n个元素中的最大元素值#include <stdio.h>#include <stdlib.h>i_锐格题库
1.安装JDK1.8,并在AndroidStudio配置JDK路径2.app build.gradle中配置defaultConfig {android.compileOptions.sourceCompatibility 1.8android.compileOptions.targetCompatibility 1.8}3.解决用JDK1.8 Lambda表达式中文乱码的...
The usage of Internet becomes one of the most controversial topics in the society. As a college student, I believe Internet is beneficial to me more than the way it harms me. There are many advantages...
解决命令的权限问题,可以扩大权限的范围比如要向 test.asc 文件中随便写入点内容,可以:$ echo "信息" >> test.csv如果将 test.asc 权限设置为只有 root 用户才有权限进行写操作:$ sudo chown root.root test.csv然后,我们使用 sudo 并配合 echo 命令再次向修改权限之后的 test.asc 文件中写入信息:$ sudo echo "hahah" >> test.csv-bash: test.asc_linux /bin/sh -c
技术路线一定是与核心技术有关的项目流程图,而实施方案则是更为详细的既包括了技术内容也覆盖了项目实施中非技术部分的详细过程。但这个描述落实到具体课题,就没有了一个唯一的标准。具体涉及到这两个内容时,确实不太好把控。关于技术路线与实施方案问题,打一个不一定恰当的比方.项目要求是走陆路从马尔康到北京.打开互联网一查公路与铁路分布看.从马尔康到成都经西安-郑州北上可到北京;从马尔康到成都...
http://www.jianshu.com/p/31de4b15b347编译安装libimobiledevice编译安装libimobiledevice在windows上大家可以使用iTunes来与iPhone进行通信,但是Linux上没有这类的官方软件,所以一些爱好者就破解了iTunes的通信协议,然后在Linux上实现了该协议,也就是libimobiledev