• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Runtime error vs Compiler error

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Huang,
Your understanding about the default constructor
is correct. It causes a compile-time error.
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic