wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes doubt about checked exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt about checked exception" Watch "doubt about checked exception" New topic
Author

doubt about checked exception

yuvraj kotegar
Ranch Hand

Joined: Jul 31, 2008
Posts: 120
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.)


[Jess in Action][AskingGoodQuestions]
yuvraj kotegar
Ranch Hand

Joined: Jul 31, 2008
Posts: 120
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

Joined: Jul 31, 2008
Posts: 120
but checked exceptions should be handeled at compile time na??
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 410

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!!!


Pawan Chopra
SCJP - DuMmIeS mInD
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38108
    
  22
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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: doubt about checked exception
     
    Similar Threads
    OOP-2 : NaturalLanguageMultiply
    method invocation problem
    Exceptions and overriding
    Explanation fro Exceptions
    Checked and Unchecked exception