• 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

confused in runtime exception and compile time exception

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am confused in CTE and RTE?
If exam question ask about which type of exception is this, so how should i answer it?

Thanks
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Imagine you build and run the code: if you encounter compilation error, it's CTE. Else, if you encounters error/exception when you run it, it's RTE.
 
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Prakash,

First, please use the full form of words, as it gets difficult for the reader to understand your short hand. It's against
javaranch policy.

Well, for the question as you have asked, you got to be aware that what kind of checked exception will be thrown and case compile time error.
For example, if an object reference is null and you try to invoke some method over it, you will get a NullPointerException which
is a run-time exception. On other hand if you are use parse function from the Date class, it shows a checked exception so if you
forget to handle it or throw it, the compiler will generate a compile time error. So you need to understand the situations yourself
to acquaint yourself with such scenarios.

Hope this helps,
 
Sheriff
Posts: 9708
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
There is runtime exception and compile time error but no compile time exception. I hope you are not talking about checked and unchecked exceptions here (one has to be handled for the code to compile, one is not)...
 
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes he looks to be talking about checked and unchecked exceptions.
 
Prakash Mahto
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, prithvi
Sorry to reply late and putting short form
It seems that it is completely on practice and self feeling to know about the differnece between compile time error and run time exception.

is there any specific list for OCPJP exam which separate these both

Thanks
 
Prakash Mahto
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Ankit for improving my mistake on Compile time Error not Exception
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(one has to be handled for the code to compile, one is not)



Just to nitpick Ankit and arise his ire, an unchecked exception can always be thrown and not handled.



of course by handled, Ankit meant that it should be thrown or caught. Just so it is clear to someone that stumbles on this thread later on.
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Prakash,

Every Exception class is derived from Throwable e.g. Error and Exception , any exception which is subclass of Exception but not subclass of RuntimeException its known as "Checked Exception" and has to be handled (either using try-catch or throws) at compile time , means if you won't provide proper code compiler will complain.

on the other hand any exception which is subclass of RuntimeException are not checked by compiler at compile time.

e.g. IOExcepiton is a checked exception (not subclass of RuntimeExcepiton) and NullPointerException is unchecked exception(subclass of RuntimeException).

hope this helps.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic