• 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

Compilation fails vs runtime exception

 
Greenhorn
Posts: 25
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My second question today... I've a hard time knowing when compilation fails and when there's a exception. Does anyone has a "simple rule" or "trick" to this?

Thnaks in advance.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those are two different things. Well, the compile errors are when you have syntax errors in your code or you have violated some rules which are mandated by the API (like handling checked exceptions etc..). RuntimException(s) occur due to unexpected behavior at runtime when your code is running, those are not checked by the compiler though.
 
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
Compilation errors are due to syntax problems, illegal access, accessing a variable when the scope has ended etc.

Runtime errors occur when a program compiles correctly but something goes wrong when the program runs. Null pointers, stack over flow, out of memory etc.

As you code more and more, the distinction will become clear. It comes with practice
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In other lay man terms, Compilation errors does NOT let your class get compiled successfully. If you use an IDE like eclipse, netbeans, IntelliJ IDEA etc., you would get a red underline on the lines which have a compiler error. Examples are given by other ranchers in the above posts.

Whereas a Runtime exception (or an error) does NOT prevent the class from getting compiled. The Java class would get compiled successfully and only at the runtime (during execution) the errors would be caught and thrown.

Does it help?
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic