• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Catching Exceptions...

 
Dan Silva
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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.
 
Dan Silva
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic