aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes help me to understand compiletime & runtimr exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "help me to understand compiletime & runtimr exceptions" Watch "help me to understand compiletime & runtimr exceptions" New topic
Author

help me to understand compiletime & runtimr exceptions

m prabhu
Ranch Hand

Joined: Jan 29, 2008
Posts: 79
hi,
so far i have been thinking

JVM thrown exceptions - Runtime exceptions
Programatically thrown - Compiletime excetions

but it is proved wrong..

how to understand this without looking into API.

Or

memorizing important exceptions type is the only way.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42595
    
  65
There's no such thing as compile-time exceptions; they're compile-time errors, which are shown by the compiler to indicate syntax errors in the source code.

Runtime exceptions can be thrown by either the JVM (or rather, the class libraries that ship with the JVM) or your own code.


Ping & DNS - my free Android networking tools app
m prabhu
Ranch Hand

Joined: Jan 29, 2008
Posts: 79
if so what is checked exceptions.

the reson for my query is:
i am not able to understand overriding concept which states
'overriding methods should not throw new checked exceptions or broader exceptions whereas it can throw any new unchecked exception or narrower exceptions or no exceptions.

[ March 25, 2008: Message edited by: m prabhu ]
[ March 25, 2008: Message edited by: m prabhu ]
Kesu sundar
Greenhorn

Joined: Mar 19, 2008
Posts: 5
Originally posted by m prabhu:
'overriding methods should not throw new checked exceptions or broader exceptions whereas it can throw any new unchecked exception or narrower exceptions or no exceptions.


This means that
if a base class method throws an an exception, and when we override the same in the sub class (method signature should be same as per rule), we have the following choices

1. use the same exception in the overrided method
2. use a subclass of base class exception
3. or no exception
4. throw an unchecked (runtime) exception.


bcos as exception propagates up in the reverse order ( from subclasses to base..) we cant have a new checked exception or a more generalised exception than base class.
[ March 25, 2008: Message edited by: Kesu sun ]
m prabhu
Ranch Hand

Joined: Jan 29, 2008
Posts: 79
i can understand the overriding rule.

what i am not understanding is how to know
-this is a unchecked exception and checked exception
Kesu sundar
Greenhorn

Joined: Mar 19, 2008
Posts: 5
Anything extending from RuntimeException class is an unchecked exception.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42595
    
  65
A checked exception extends java.lang.Exception. The Java compiler requires these to be declared to be thrown, or handled by a try/catch statement.

Unchecked exceptions extend java.lang.RuntimeException, and are not required to be handled by the code.

You can read the javadocs for the RuntimeException and Exception classes for more information on how to use each one.
Pranav Bhatt
Ranch Hand

Joined: Mar 20, 2006
Posts: 284
Read just above the screenshot of the below post with same heading as below-:
How do I know if it is a checked exception or an unchecked exception?
m prabhu
Ranch Hand

Joined: Jan 29, 2008
Posts: 79
Hi,
thank you for everybody.
especially the link is very useful.

thank you.
Nadeem Khan
Ranch Hand

Joined: Nov 27, 2007
Posts: 108
I agree with Ulf. Its all you need to know for SCJP 5.0. BTW I didnt encounter a single question to differentiate b/w checked & unchecked.


<i>If there were no Exceptions (not Errors!), Life would have kinda sucked!!</i>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help me to understand compiletime & runtimr exceptions