• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

difference b/w Runtime and compile time exceptions?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to know whether an Exception is a Runtime exception or Compile time exception....? How to differentiate between them......?its confusing me a lot.......!!!
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Ranch Hand
Posts: 449
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic