• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When a compiler error vs when a runtime error

 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In going through these mock exams, I find a lot of questions dealing with compile time errors and run time errors. What is a general rule of thumb for when to expect a compile time error and when to expect a run time error
-Dale
------------------
What's this H2SO4 doing in my fridge?? ( thud )
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, a compile time error usually happens when you are compiling it.
A run time error usually happens when you are running it.
 
Charlie Swanson
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a hard time with determining if it would be a compile time error or a run-time error.
I do know that the compiler tries to find as much as it can. But, many things for example, things that have to do with the live object being used can only be determined at run-time.
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly my point. I'd like to find a general rule to figure out if something would generate a run-time error or a compile-time error.
-Dale
------------------
What's this H2SO4 doing in my fridge?? ( thud )
 
Marilyn de Queiroz
Sheriff
Posts: 9061
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the superclass of the Exception that is being thrown. Check the API
for the Exception you are wondering about to see whether it inherits from RuntimeException or not. If it does not, it is a compile-time Exception.
 
sona gold
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all errors related to syntax of commands are compile time
there are more but this one if one of them
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compile time errors - caused by errors in syntax or breaking rules that a, for lack of a better term, "well-formed" java program should follow. Things like illegal type conversions, typos, missing parenthesis, redeclaration of variables, etc. that the compiler can determine to be incorrect during compile time. Can usually be traced back to one line in particular.
Runtime errors are usually related to logic errors. The syntax may be correct and the error may be thrown at a particular line of code, but the cause may be due to the logic encompassed by several lines of code. Things like off-by-one loop errors, improperly casting objects, invoking a method on a null object reference would produce runtime errors.
A clarification to what Marilyn said above: All exceptions occur at runtime. The difference is that the compiler will complain about code that does not explicitly catch Checked exceptions.
Junilu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic