try{} catch{} finally{} 语句注意事项总结
来源:互联网 发布:超级基因优化液txt全集下载 编辑:程序博客网 时间:2024/04/28 02:08
- 如果有一个catch{}语句匹配上,其他catch{}分支就不会执行了
- try{}里面如果有return,也会先执行finally{}里面的语句,之后再return
- 如果try{}和finally{}里面都与return语句,则try{}里面的return不会被执行
- finally{}部分什么情况下不会被执行?
- 在try{}之前就return的情况
- 在try{}里面有System.exit()的情况
- 线程被interrupted/killed的情况
- 死机、停电
- 如果在finally{}里面出现异常,有什么后果?
- 会覆盖try{}里面的异常,导致try{}里面的异常无法被捕捉到
- 会导致finally{}异常后面的代码不会被执行
- 会被调用者捕获
- 如果在finally{}里面会出现异常,怎么解决?
- 留给调用者去解决
- 在finally{}里面捕获后,写进日志里面
The finally Block
The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs. But finally is useful for more than just exception handling — it allows the programmer to avoid having cleanup code accidentally bypassed by a return,continue, or break. Putting cleanup code in a finally block is always a good practice, even when no exceptions are anticipated.
Note: If the JVM exits while the try or catch code is being executed, then the finally block may not execute. Likewise, if the thread executing the try or catch code is interrupted or killed, the finally block may not execute even though the application as a whole continues.
- try{} catch{} finally{} 语句注意事项总结
- try{} catch{} finally{} 语句注意事项总结
- 黑马程序员--Try...catch...finally语句总结
- try..catch..finally语句
- try-catch-finally语句
- try{}catch(){}finally语句块
- JavaScript try/catch/finally 语句
- try catch finally 语句详解
- JavaScript try/catch/finally 语句
- try...catch...finally语句块
- try...catch...finally语句块
- try...catch...finally中的执行顺序和return语句 总结
- try - catch - finally使用总结
- try...catch...finally分析总结
- try,catch,finally代码总结
- Try.Catch.Finally简单总结
- 异常处理的try-catch-finally语句
- 捕获异常语句try..catch..finally..
- Theano2.1.12-基础知识之使用GPU
- php将数据写入excel
- 机器学习算法与Python实践之(七)逻辑回归(Logistic Regression)
- zTree—一次性加载树
- Mongodb的副本、分片搭建方式
- try{} catch{} finally{} 语句注意事项总结
- Uva - 725 - Division
- 用scrapy框架时,出现问题:ValueError: invalid literal for int() with base 10: 'dev0'
- Android中继承RadioButton后,点击不能选中
- 微信公众平台java开发详解(工程代码+解析)
- [DP][RQNOJ 3822]选择题
- 【emoji表情】阿里云数据库RDS支持emoji表情
- 初步认识BLE到熟悉,浅谈!
- Leetcode—Contains Duplicate—Python的三种写法