• 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

SCJP2 Question - Compiler Error Vs. Run-time Error

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a rule of thumb to distinguish between Compiler Error Vs. Run-time error.
Syntax errors obviously generate Compiler errors. Apart from Syntax errors, how can you say whether a particular group of code produces compiler or Run-time error ?
Thanks.
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A NullPointerException would be a standard run-time error.
 
Anurag Swaym
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question was specific for Java certification exam. You know that a block of code is incorrect and is going to generate some errors.
My question is: Is there a logical way, by which you can predict that this block of code is going to generate compiler error as opposed to run-time error.
Thanks
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wellcome to the Ranch swamyarun
Please read about our name policy and adjust your displayed name accordingly.
Experience will tell you which exceptions are runtime or not.
In the meantime consider if it is feasible to force a try clause, each time the exception could be arised in the program. For instance, a NullPointerException being a checked one would force to put all the method invocations within a try, or declare it in the method. Not feasible, thus, it is a RuntimeException.
Also remember that certain actions will always imply such risk, that the exceptions they could arise are checked by the compiler for you not forgetting about them. Forgetting about managing them, I mean. That is the case of the actions that have to access the file system and the IOException.
Now I see that my answer is not very related to your question.
I will keep it anyway for the benefit of others.
[ August 12, 2002: Message edited by: Jose Botella ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got me sort of worried for a few seconds!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's many errors in semantics that the compiler can discover too. As you learn the language and compile code you are going to get some the compiler errors. Some are going to stick in your head.
What I do is learn a bit from one of the well known Java books, code a bit, then I pick up the Java Language Specification and try to get a more deeper understanding of a topic. The JLS is full of "It is a compile time error to ...".
No easy way to do it, like making money.
-Barry
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Distinguising between code that will compile, or not, and the one generating exceptions is of paramount importance for the exam.
There isn't a unique rule for that. However while studying the Java language, the sooner someone is aware of the compiler error/runtime exception dichotomy, the sooner he will begin to really understand the language. That is, while examining a Java piece of code first think if the code compiles, and then if the code will execute. But do these in two different steps.
For instance, the compiler checks for the existance and accesibility of all the expressions that access members of a class. In this case the "interpreter" has nothing to do with it.
Casting is an area where distinguishing, when the compiler will complain -and when ClassCastException is thrown, requires a good understanding of what will compile, and if does so -the second step, what will run.
I am sorry no magic wand for that. Each case must be studied separately.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic