0
Exception to throw for missing input from scanner
I wanted to make a program not crash when it doesn't get the input (String) it needs... while(true){ try{ str = scan.nextLine(); } catch(/*The exception I don't know and didn't find*/ e) { System.out.println("Missing Input. Please try again"); continue; } break; }
3 Antworten
+ 3
Just use "catch(Exception e)". The word "Exception" is made to handle all possible exceptions that might occur.
+ 2
you can also check if there is a next line, scanner.hasNextLine(). Returns a boolean if it has a next line
0
Thank you both!