aspose file tools*
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
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: 19670
    
  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!
 
 
subject: Catching Exceptions...