Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Compiler Error & Runtime Exception

 
Poonam Krishnam
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to know the difference between Compiler Error & Runtime Exception.
Given a faulty program that how do you identify if it is a Compiler Error or a Runtime Exception ?
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Poonam,

Compiler error could be a syntax error
1. Left curly braces not equal to right curly braces.
2. Semicolon missing in the end.
3. identifiers starting with digits.
4. Using wrong modifiers (top level class private) or wrong combination of modifer (abstract with static).

These are some error which compiler can catch.

In short compiler error are those which directly violate any rule of java language specification.

Whereas exception comes when something goes wrong at the time of execution of your code.
You code is fine as per JLS but may be you are doing 1/0 arithmetic operation or loading any class or file which does not exist.



Compiler can't report these errors unless and until you programme not gets executed. We call these types of errors as Exception.

"By the way its not certification question at all. Its java beginner question" and we have separate forum for that.


Naseem
[ July 13, 2006: Message edited by: Naseem Khan ]
 
wise owen
Ranch Hand
Posts: 2023
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic