aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "main() method throws exception" Watch "main() method throws exception" New topic
Author

main() method throws exception

venkatesh pendharkar
Ranch Hand

Joined: Apr 29, 2006
Posts: 106
hi
I would like to know how come main() method can throws exception
eg.
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
Greenhorn

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
practice question on try catch
wait() method question
Nested try/catch block
A possible wrong answer in ExamLab?
Question from Exam Lab (Exception Handling)