Exception handling | Sololearn: Learn to code for FREE!


Exception handling

Can we handle any exception without using catch block?..if yes then how?

12/13/2019 10:41:09 AM

Giriraj Nagar

2 Answers

New Answer


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


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.