wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes main() method throws exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "main() method throws exception" Watch "main() method throws exception" New topic

main() method throws exception

venkatesh pendharkar
Ranch Hand

Joined: Apr 29, 2006
Posts: 106
I would like to know how come main() method can throws exception
public static void main(String[] args) throws InterruptedException
throw new InterruptedException();
if main() method throws exception then who catches it??JVM??Can anyone please explain me the logic behind it.
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

If an exception is always handled using the throws clause, then eventually the exception will propagate all the way back to the main method of the application. If the main method throws the exception and the exception actually occurs while the program is running, then the program will crash.

See this link for more details : http://www.cs.wisc.edu/~cs302/io/Exceptions.html

Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
venkatesh pendharkar
Ranch Hand

Joined: Apr 29, 2006
Posts: 106
Thanks Krishna for your reply
Cherry Singhal

Joined: Sep 05, 2006
Posts: 6
Hi krishna,
So that means nothing catches the exception?
& by crashing you mean we get a corresponding runtime exception?
Don't get me started about those stupid light bulbs.
subject: main() method throws exception
Similar Threads
wait() method question
A possible wrong answer in ExamLab?
practice question on try catch
Question from Exam Lab (Exception Handling)
Nested try/catch block