gpt4 book ai didi

java - 访问 wobblyMethod() 中的局部变量

转载 作者:行者123 更新时间:2023-12-02 13:11:44 25 4
gpt4 key购买 nike

我对如何从 wobblyMethod() 内部访问数组 a 感到困惑,因为我的异常。我需要一个长度来完成这个问题。我已经概述了我的问题

enter image description here

我的代码如下:

public String wobblyMethodHandler(){

try{
wobblyMethod();
String b = "No exception";
return b;
}
catch(IndexOutOfBoundsException e){
String h = "Array index " + " out of bounds!";
return h;
}
catch(Exception e){
String g = "Exception!";
return g;
}
}

如何获取该数组的长度?

最佳答案

这不是您想要的数组的长度,而是您尝试访问的无效单元格(这只是巧合,值“3”也是数组的长度)。将您的代码更改为:-

...
catch(IndexOutOfBoundsException e){
String h = "Array index " + e.getMessage() + " out of bounds!";
return h;
}
...

关于java - 访问 wobblyMethod() 中的局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43933908/

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