Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt about checked exception

 
yuvraj kotegar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose you throw a checked exception out of the main method also... i mean you do want to handle it there.
will the JVM handle it suppose it occurs there??


now suppose exception occurs somewhere and reaches the main method and if the main method also throws it out will the jvm handle it like RuntimeExceptions??
[ November 02, 2008: Message edited by: yuvraj kotegar ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Easy enough to try the experiment, yes?

If main() declares that it throws an exception, and indeed, at runtime an exception occurs, then the JVM prints the stack trace of the exception and the main thread halts (i.e., for simple programs, the JVM exits.)
 
yuvraj kotegar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi thanks for the quick reply

i knew that runtime exceptions can be handled by the jvm. just had a doubt with checked exceptions.

Thanks for the reply
 
yuvraj kotegar
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but checked exceptions should be handeled at compile time na??
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the JVM method who is invoking main() method in java has already handled Exception internally , by handling the parent class of all java.lang.Exception. But I am not sure , it should be like this. If any body can answer this, that will be great!!!
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says somewhere in Thinking in Java by Bruce Eckel that when an Exception reaches the JVM it does two things:
  • 1: Print the stack trace.
  • 2: Stop the thread the Exception was thrown in.
  • If you have a single-threaded application that means it stops the entire application and the JVM exits.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic