0
Exception handling
Can we handle any exception without using catch block?..if yes then how?
2 ответов
+ 2
You can assign the exception right after the function name using the throws keyword
Scanner sc = new Scanner(System.in);
int getInput() throws IOException {
int x = Integer.parseInt(sc.nextLine()) ;
return x;
}
+ 2
Just like HNNX 🐿 mentioned you can either use a "throws" keyword with the method declaration or you need to handle it with a try catch block inside the method.