• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime error vs Compiler error

 
Chung Huang
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it safe to say that in general a compiler error resulted from codes that do not make sense in its syntax, while runtime error is the result of poor logic?
I would like to know if there is a generalized way to determining if a given code would generate compiler error or runtime error.
A related question, so what if the parent class has no default no arg constructor and the child class has no constructor? As far as I can tell, this would be a compiler error since compiler would put in a call for the default no arg constructor in the child class, which means invoking a non-existing constructor in the parent class. Is this right?
[ June 22, 2002: Message edited by: Chung Huang ]
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chung Huang:
Is it safe to say that in general a compiler error resulted from codes that do not make sense in its syntax, while runtime error is the result of poor logic?

... I guess... in most cases, but what about exlpicit / implicit casting of primitives? those kind of things require a lot of memorization.
 
Alan Chong
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Huang,
Your understanding about the default constructor
is correct. It causes a compile-time error.
 
Paul Villangca
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chung,
With compile-time vs. runtime errors (or exceptions), I think it's not as clear-cut an explanation as you have said. Compile-time errors include not handling a checked exception. Runtime errors include failure to read from a file or stream.
IMO, The best way to determine whether an error is generated at compile-time or at runtime is to experience them yourself. Write and run some code and see for yourself.
 
Kumar Kausikasa
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
You are correct. Compilation errors occur when your syntax is not right or not allowed. Run time errors occur when you are executing and these might be due logical errors ( semantic), the data required is not available, corruption of data (mainly which invovles remote method invocations and data is serialized).
For example , if you are working with sockets and trying to connect to a server, the program would throw a run-time exception , if server is not running for any reason.
My idea of posting this message, is to emphasize that run-time errors occur not only due to logical errors , but might also depend on other factors (like network connection, object serilization etc)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic