GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes difference b/w Runtime and compile time 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 "difference b/w Runtime and compile time exceptions?" Watch "difference b/w Runtime and compile time exceptions?" New topic
Author

difference b/w Runtime and compile time exceptions?

Naveen Megharaj
Ranch Hand

Joined: Feb 13, 2009
Posts: 39
how to know whether an Exception is a Runtime exception or Compile time exception....? How to differentiate between them......?its confusing me a lot.......!!!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Well I think first you need to use the correct vocabulary. There are no compile time exceptions. There are checked exceptions which the compiler checks that you handle properly i.e. the compiler checks where they can occur and there are proper try-catch block or throws clause to handle them. Then there are unchecked exceptions which are not checked by the compiler i.e. the compiler doesn't check where they can occur and doesn't care if there are try-catch or throws for them.

That's the end of the story but if you are confused between JVM exceptions and programmatic exceptions. JVM exceptions are thrown by the JVM at runtime. Like ArrayIndexOutOfBoundsException or ClassCastException. These are thrown when something unexpected happens. These are limited in number and are unchecked. Programmatic exceptions are thrown using a throw statement. They are not automatically thrown by the JVM. These are large in number and can be checked or unchecked. The list of programmatic and JVM exceptions covered in the exam is given in K&B. So you don't need to know about all the exceptions that there are in the API...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
mansi gupte
Ranch Hand

Joined: Dec 30, 2008
Posts: 72
Naveen Megharaj wrote:how to know whether an Exception is a Runtime exception or Compile time exception....? How to differentiate between them......?its confusing me a lot.......!!!


Errors are categorised as either runtime or compile time.

For exceptions the category would be

1] Programmatic -- exception that is expected to be handled/ declared or both by the programmer.

2] Runtime -- runtime exception may or may not be declared by the programmer[ that is there is no compulsion of that sort].

Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Naveen Megharaj wrote:how to know whether an Exception is a Runtime exception or Compile time exception....? How to differentiate between them......?its confusing me a lot.......!!!


If i am not wrong then the answer would be:

The Java programming language provides three kinds of throwables : checked exceptions, runtime exceptions, and errors.

You should use checked exceptions for conditions from which the caller can reasonably be expected to recover.

From the JLS: "This compile-time checking for the presence of exception handlers is designed to reduce the number of exceptions which are not properly handled."

If you are throwing an exception for an abnormal condition that you feel client programmers should consciously decide how to handle, throw a checked exception. Unchecked exceptions indicate software bugs. Precisely because unchecked exceptions usually represent software bugs, they often can't be handled somewhere with more context.

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked.

You can find more information here


http://muhammadkhojaye.blogspot.com/
Vishwajeet Nambiar
Greenhorn

Joined: May 23, 2009
Posts: 1
Well I think first you need to use the correct vocabulary. There are no compile time exceptions. There are checked exceptions which the compiler checks that you handle properly i.e. the compiler checks where they can occur and there are proper try-catch block or throws clause to handle them. Then there are unchecked exceptions which are not checked by the compiler i.e. the compiler doesn't check where they can occur and doesn't care if there are try-catch or throws for them.

That's the end of the story but if you are confused between JVM exceptions and programmatic exceptions. JVM exceptions are thrown by the JVM at runtime. Like ArrayIndexOutOfBoundsException or ClassCastException. These are thrown when something unexpected happens. These are limited in number and are unchecked. Programmatic exceptions are thrown using a throw statement. They are not automatically thrown by the JVM. These are large in number and can be checked or unchecked. The list of programmatic and JVM exceptions covered in the exam is given in K&B. So you don't need to know about all the exceptions that there are in the API...


Good Explanation..Here is a link from the Sun site that could help..Exceptions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference b/w Runtime and compile time exceptions?