在try / catch中捕获异常后继续执行循环

问题描述:

一旦在此代码中捕获到异常,就会运行 menuSystem 方法,但是一旦我输入一个数字,程序就会关闭并且Build is successful消息被展示。一旦发生异常,有没有办法重新进入while循环?

Once an exception is caught in this code, the menuSystem method is run, but once I go to input a number the programme closes and the "Build is successful" message is displayed. Is there any way to get back into the while loop once an exception has occured?

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();
   }
}


put while循环中的尝试/抓取

    while (option != 0) {
        final Scanner keyb = new Scanner(System.in);
        System.out.println("");
        try {
            switch (option) {

            }
        } catch (Exception InputMismachException) {
            System.out.println("\nPlease Enter a Valid Number\n");
            option = menuSystem();
        }
    }