Can we handle an exception thrown out of main? If yes, how? | SoloLearn: Learn to code for FREE!

+3

Can we handle an exception thrown out of main? If yes, how?

5/15/2020 8:23:55 AM

Sandeep Kushwaha

2 Answers

New Answer

+1

You can throw an exception from main, but where would you catch it? The JVM handles all uncaught exceptions. When an exception is thrown it can either be handled directly within the method in which it was thrown or passed up the method call stack until it reaches a method that handles it. If not handled in any method prior to main or within main then it will be thrown from main to the JVM to be handled.

+3

Use try catch block https://www.sololearn.com/learn/Java/2175/