gpt4 book ai didi

Java:Try/Catch 语句:捕获到异常时,是否重复 try 语句?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:13:45 26 4
gpt4 key购买 nike

<分区>

有什么办法吗?

//Example function taking in first and last name and returning the last name.
public void lastNameGenerator() throws Exception{
try {
String fullName = JOptionPane.showInputDialog("Enter your full name");
String lastName = fullName.split("\\s+")[1];
catch (IOException e) {
System.out.println("Sorry, please enter your full name separated by a space.")
//Repeat try statement. ie. Ask user for a new string?
}
System.out.println(lastName);

我想我可以为此使用扫描仪,但我只是好奇是否有办法在捕获异常后重复 try 语句。

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