wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Runtime error vs Compiler error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Runtime error vs Compiler error" Watch "Runtime error vs Compiler error" New topic
Author

Runtime error vs Compiler error

Chung Huang
Ranch Hand

Joined: Jun 21, 2002
Posts: 56
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 ]

Let us be showered in the light of confusion!
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

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

Joined: Jun 05, 2002
Posts: 106
Hi Huang,
Your understanding about the default constructor
is correct. It causes a compile-time error.
Paul Villangca
Ranch Hand

Joined: Jun 04, 2002
Posts: 133
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

Joined: Jun 04, 2002
Posts: 45
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runtime error vs Compiler error