Java的try-catch-finally
如下引用文章:https://help.semmle.com/wiki/display/JAVA/Finally+block+may+not+complete+normally
A finally block that does not complete normally suppresses any exceptions that may have been thrown in the corresponding try block. This can happen if the finally block contains any return or throw statements, or if it contains any break or continue statements whose jump target lies outside of the finally block.
Recommendation
To avoid suppressing exceptions that are thrown in a try block, design the code so that the corresponding finally block always completes normally. Remove any of the following statements that may cause it to terminate abnormally:
returnthrowbreakcontinue
举例子:
try {}
catch (Exception e) {}
finally {
throw new Exception() ;
}
try {}
catch (Exception e) {}
finally {
return;
}
L:
try {}
catch (Exception e) {}
finally {
break L;
}
try {}
catch (Exception e) {}
finally {
try{
throw new Exception() ;
}catch(Exception e){
}finally{
return;
}
}
都会出现警告信息finally block does not complete normally,如下则不会:
try {}
catch (Exception e) {}
finally {
try {
throw new Exception();
} catch (Exception e) {
}
}
try {}
catch (Exception e) {}
finally {
L: {
break L;
}
}
关于try-catch-finally的执行流程图如下:

Java的try-catch-finally的更多相关文章
- 【转】Java中try catch finally语句中含有return语句的执行情况(总结版)
Java中try catch finally语句中含有return语句的执行情况(总结版) 有一点可以肯定,finally块中的内容会先于try中的return语句执行,如果finall语句块中也有r ...
- Java 异常处理 try catch finally throws throw 的使用和解读(一)
//最近的一个内部表决系统开发过程中,//发现对异常处理还存在一些模棱两可的地方,//所以想着整理一下//主要涉及到://1.try catch finally throws throw 的使用和解读 ...
- JEECG&JWT异常捕获强化处理 | Java: Meaning of catch (final SomeException e)?
//从header中得到token String authHeader = request.getHeader(JwtConstants.AUTHORIZATION); if (authHeader ...
- Java中try,catch,finally的用法
Java中try,catch,finally的用法,以前感觉还算熟悉,但看到一篇博文才有更深点的理解,总结网友博客如下. Java异常处理的组合方式: 1.try+catch 运行流程:运行到try ...
- java中 try catch finally和return联合使用时,代码执行顺序的小细节
代码1测试 public static void main(String[] args) { aa(); } static int aa() { try { int a=4/0; } catch (E ...
- java异常处理try catch finally
1 异常 1.1 异常处理的作用 在编程时,如果出现文件打开失败,读写文件就会异常退出.如果出现内存溢出错误,程序也会异常退出.如果不能对这些异常进行处理.程序则无法正常运行.所 ...
- Java try和catch的使用介绍
尽管由Java运行时系统提供的默认异常处理程序对于调试是很有用的,但通常你希望自己处理异常.这样做有两个好处.第一,它允许你修正错误.第二,它防止程序自动终止.大多数用户对于在程序终止运行和在无论何时 ...
- Java中try catch finally语句中含有return语句的执行情况(总结版)
在这里看到了try >但有一点是可以肯定的,finally块中的内容会先于try中的return语句执行,如果finall语句块中也有return语句的话,那么直接从finally中返回了,这也 ...
- Java如何使用catch来处理异常?
在Java编程中,如何使用catch块来处理异常? 此示例显示如何使用catch来处理异常. package com.yiibai; public class UseOfCatch { public ...
- 深入剖析java的try…catch…finally语句
一.前言 前些天参加面试的时候有一道题: public class test { public static void main(String[] args){ try { return; } fin ...
随机推荐
- tar、7z(7zip)压缩/解压缩指令的使用
本文介绍tar.7z指令的使用方法 tar指令 在Linux中,使用的最多的压缩/解压缩指令就是tar指令了. tar指令用来将多个文件/目录结构打包.在实际使用中,往往使用tar对压缩的支持,即同时 ...
- jacob将word转换为html
1.导包jacob.jar 2.将下面两个文件复制到C:\Windows\System32路径下 3.代码如下 // 8 代表word保存成html public static final int W ...
- OpenGL常用的函数
OpenGL常用的函数 1. void glBegin(GLenummode) void glEnd(void) 参数说明: mode:创建图元的类型.可以是以下数值 GL_POINTS:把每一个顶点 ...
- AtCoder - 4351 Median of Medians(二分+线段树求顺序对)
D - Median of Medians Time limit : 2sec / Memory limit : 1024MB Score : 700 pointsProblem Statement ...
- 『IOS』 遇到问题记录(长期更新)
遇到的很多问题,解决后都是自己记着,以为不会忘记,之后却会想不起来了. 所以把今后解决的问题记录在这. 一. 在二级页面设置了CAlayer的代理,在返回一级页面报错: EXC_BAD_ACCESS( ...
- Trystrtofloat
TryStrToFloat为 ‘+1’和‘-1’和 ‘.1’是可以装换成功的
- 用input标签 文件,多文件上传
单个文件,多个文件区别不大,只是需要把多个文件装在一个容器里面,循环遍历即可: 需要注意的 input 标签中name属性,一定要指定: 在这是 fileBase 需要确定method必须是pos ...
- asp.net 下载EXCEL文件
一.需要导入NPOI 库文件 打开VS2012 工具>>库程序包管理器>>管理解决方案的NuGet程序包,搜索NPOI,如下图 安装完成: 添加 using NPOI.HSSF ...
- [.net]数组
在C语言中,数组是比较简单,也使用比较多的一种基础的数据结构.常用的有一维数组,二维数组等.但是在C#中,使用最多的是List,Dictionary等一些集合类,因为用他们来操作同类型的数据,比数组更 ...
- 【cocos2d-x 手游研发小技巧(2)循环无限滚动的登陆背景】
原创文章,转载请附上链接:http://www.cnblogs.com/zisou/p/cocos2d-xARPG6.html 首先让大家知道我们想要实现的最终效果是什么样的? 看一个<逆天仙魔 ...