• 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

question about compile error or runtime error

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the error happens ?At compile time or runtime ?How can I get it clear?Has it regularity or not?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ji,
I didn't really get your question. Do you have a specific scenario in your mind (then give us some code) or you're just wondering what's the difference between compile-time and run-tim errors?
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compile time error happens when your program has one or more syntax errors.
What is syntax error? Every programming language dictates how you should write your program. If you want drive a car without getting booked in front of the watchful police officer than you don't jump the red lights. If you don't want the compiler errors than you follow the Java rules book (jls).

Runtime error occurs when you violate the rules during the execution of the program. In order to run the program, it should pass the compiler first. So, it doesn't have any syntax violatations.
 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simply compile time errors occur when the thing being checked by the compiler can be determined by the compiler during compile time. This is like the syntax of the program, checked exceptions handeling, a call to a non-static variable from the static context, mis-overloading a method, wrong declaration, etc... all these things can be checked by the compiler during compile time and thus you get a compile time error while compiling your code. Compiler though can't catch things that are only determined during run time.
Runtime errors are due to errors that can only be determined by the JVM when running the program, like dividing by a variable that equals to zero, compiler can't determine the value of the variable during compilation cause the compiler doesn't check the real life behavior of your code.
You should know when can compile time errors happen and when does runtime erros occure, you might have to choose between this or that in a question in the exam.
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One particular example of when people are tripped on this is in regard to conversion and casting.
A conversion must be correct at compile time. A cast is a directive to the compiler to ignore a possible conversion error and to let the JVM decide if its correct at runtime.
"What we observe is not nature itself, but nature exposed to our method of questioning,"
--- Werner Heisenberg ---
Ken
SCJP 1.4
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic