在java中,我想从一个特定的语句块跳到另一个语句块。我怎样才能做到呢?

在java中,我想从一个特定的语句块跳到另一个语句块。我怎样才能做到呢?,java,Java,实际上,我想做的是,当发生异常时,我希望在该异常之后继续下一个语句。 有什么方法可以用Java实现吗?您只需要输入System.out.println(a) 将它放在finally块中意味着即使在没有发生异常的情况下也会执行它。只有在发生异常时,程序才会转到catch块。尝试以下操作 public class abc{ public static void main(){ try{ int a =10; if(a=

实际上,我想做的是,当发生异常时,我希望在该异常之后继续下一个语句。
有什么方法可以用Java实现吗?

您只需要输入
System.out.println(a)

将它放在finally块中意味着即使在没有发生异常的情况下也会执行它。只有在发生异常时,程序才会转到catch块。

尝试以下操作

public class abc{
    public static void main(){
       try{
               int a =10;
               if(a=10){
               throw new Exception();
       }
               l1:System.out.println(a);
       }catch(Exception e){
               continue l1;
       }
    }
}

无论如何,在java中避免跳跃

我想这就是你想要的

int a =0;
 try{
           a =10;
               if(a=10){
               throw new Exception();
}
        } catch(Exception ex){
            //do nothing
        } finally {
             l1:System.out.println(a);
        }
或者如果a是10

    public static void main(String[] args) {
    int a = 9;
    try {
        if (a == 10) {
            throw new Exception();
        }
    } catch (Exception e) {
        e.printStackTrace(); // only if there is any exception
    } finally {
        System.out.println(a); // always print this message
    }
}

使用
finally
执行语句,无论是否出现异常当您说“我希望继续ne语句”时,您的意思是“l1:System.out.println(a);”?如果是,finally语句可以解决此问题。是否正在查找
finally
块?是否尝试finally。。如果不是,您仍然可以使用标志;)
a
不在
finally
子句的范围内。
    public static void main(String[] args) {
    int a = 10;
    try {
        if (a == 10) {
            throw new Exception();
        }
    } catch (Exception e) {
        e.printStackTrace(); // only if there is any exception
    } finally {
        System.out.println(a); // always print this message
    }
}