Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

How to guess exception

 
Ranch Hand
Posts: 643
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ,

how to guess if the exception is thrown at runtime or compiletime.

If we try to create the instance of DateFormat class for example lets take an example



Then how would i come to know that there is runtime exception or compile time exception

Thanks
Chetan
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Compile time errors(not exceptions) will come due to incorrect syntax.
Runtime Exceptions will be thrown if the usage is wrong at runtime like invoking a null object.

First we should know the correct syntax so that we would be able to find out if there are any compiler errors.
If there are no compile time errors, then we have to follow the logic in the program to find out if there can be any runtime exceptions.

IN your example, as DateFormat class is an abstract class, you cant instantiate it! so it will give compiler error!

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

M Srilatha wrote:Hi,

Compile time errors(not exceptions) will come due to incorrect syntax.
Runtime Exceptions will be thrown if the usage is wrong at runtime like invoking a null object.

First we should know the correct syntax so that we would be able to find out if there are any compiler errors.
If there are no compile time errors, then we have to follow the logic in the program to find out if there can be any runtime exceptions.

IN your example, as DateFormat class is an abstract class, you cant instantiate it! so it will give compiler error!



I think he meant checked exception here - the exception you must need to catch or "throw" (with throws keyword) to compile your code.

The answer to asked question is, you'll need to "remember" which exception is RunTimeException & which is not.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic