Meaningless Drivel is fun!
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
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: 1850

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 :

Krishna Srinivasan
OCAJP 7/8 Exam, 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?
I agree. Here's the link:
subject: main() method throws exception
It's not a secret anymore!