wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Catching Exceptions... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Catching Exceptions..." Watch "Catching Exceptions..." New topic
Author

Catching Exceptions...

Dan Silva
Ranch Hand

Joined: Sep 05, 2007
Posts: 86
What happens when main() throws an exception? And, is it not required for a try/catch of main() throws the exception? Thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

If the main method throws an exception, the exception's stack trace is printed and the JVM exits immediately.

Second, the main method is just like any other method as exceptions are concerned - it must either be caught or declared to be thrown. Now the latter is allowed because the JVM expects any throwable - the behaviour is the above for all types of exceptions.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Rob]: If the main method throws an exception, the exception's stack trace is printed and the JVM exits immediately.

The JVM exits only if there are no other non-daemon threads running. Since this is Beginner maybe we should just say that the JVM exits as long as you aren't using multiple threads.


"I'm not back." - Bill Harding, Twister
Dan Silva
Ranch Hand

Joined: Sep 05, 2007
Posts: 86
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Catching Exceptions...
 
Similar Threads
java class not found error
If main throws exception ...
OCPJP 6 Practice exams, exam 2 q 29 error
OCP JP Practice Exam 2 #29
Exception