gpt4 book ai didi

java - 从 try block 跳转到 finally block

转载 作者:行者123 更新时间:2023-12-03 20:26:26 24 4
gpt4 key购买 nike

我正在尝试执行以下操作:

String txt = "begin\n";

try{

// some stuff

if(some condition)
JUMP TO FINALLY CODE

// some other stuff

} finally {

String txt += "end\n";
return txt;

}

有没有办法实现 JUMP TO FINALLY CODE不引发异常(在我看来引发异常看起来不干净)

最佳答案

是的,一种方法是仅 return从这样的方法

String txt = "begin\n";

try{

// some stuff

if(some condition)
return;

// some other stuff

} finally {

String txt += "end\n";

}

关于java - 从 try block 跳转到 finally block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26213774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com