Exception handling | SoloLearn: Learn to code for FREE!

0

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

+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.