try catch里面再写try catch
时间: 2023-10-21 09:27:43 浏览: 105
在try catch中再写try catch是完全合法的。这种嵌套的结构可以帮助我们更好地处理异常。根据引用的结论1,外层try catch里面可以嵌套try catch。当内层try catch捕获到异常时,外层try catch不会捕获异常,而是会随着代码的继续执行。如果内层try catch未能捕获到异常,则会触发外层的try catch,外层catch会尝试捕获异常。所以,嵌套的try catch可以提供多层异常处理的机制,帮助我们更好地控制程序的流程。参考引用的结论2和结论3。<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* [问题杂谈(三十三)多个try catch的嵌套问题](https://blog.csdn.net/qq_44648936/article/details/130743103)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [try 与catch的作用](https://blog.csdn.net/weixin_30535167/article/details/96606237)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文