一旦在此代码中发现异常,将运行menuSystem
方法,但是一旦我输入一个数字,程序就会关闭并显示“Build is successful”消息。一旦发生异常,有什么办法可以回到while循环?在try/catch中捕获异常后继续执行循环
public static void main(String[] args) {
final UnitResults myUnit = new UnitResults(10, "Java");
int option = menuSystem();
try {
while (option != 0) {
final Scanner keyb = new Scanner(System.in);
System.out.println("");
switch (option) {
}
}
} catch (Exception InputMismachException) {
System.out.println("\nPlease Enter a Valid Number\n");
option = menuSystem();
}
}
您想将try/catch放在while循环中 – antlersoft
请在公共论坛上寻求帮助时更好地格式化您的代码。 – Perception
如果你正确地缩进你的代码,你将不需要那些冗余的'// end loop','// end switch'等注释。 –