Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When is it a compiler error and when is it a runtime exception?

 
Mike Vella Zarb
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am currently studying for the SCJP certification using the Sierra and Bates Study Guide and in many of the self tests (mock exam questions) I keep running into the same problem - I can't tell whether a particular error will be at runtime (an exception) or at compile (compile error). I know this is a bit of a vague question and that it might not be possible to answer but, how can I tell if it's at compile or at runtime? Would you be able to send me some website links that might be able to help me?

Thanks in advance,
Mike
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant see anything in your question. the blind answer is www.google.com
 
Mike Vella Zarb
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I searched on Google before I asked but could not really find anything helpful - some questions need a long explanation and not just a few search key words. I was hoping that someone might be able to explain it to me in their own words. I'm sorry if you don't see anything in my question, but I did try to explain myself as clearly as possible...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, ok.

this is my short explanation:

1. compile time error:thrown by compiler while interpreted, if any syntax error in your code. programmer is responsible to clear this error

2.exception/runtime error : thrown by JVM in some exceptional condition. this error may occured due to programmer mistake or internal problem like hardware failure, no memory etc...

<edit>is it help you? </edit>
 
Vaibhav Mittal
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might find link useful.
 
Mike Vella Zarb
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:Hmm, ok.

this is my short explanation:

1. compile time error:thrown by compiler while interpreted, if any syntax error in your code. programmer is responsible to clear this error

2.exception/runtime error : thrown by JVM in some exceptional condition. this error may occured due to programmer mistake or internal problem like hardware failure, no memory etc...

<edit>is it help you? </edit>

Thanks, but I'm looking for a way to tell which one is which. I get many multiple choice questions in sample tests and they give me the choice of either Compile-time Error or Runtime Error. I know there's an error, but when is it set off is the hard part...
 
Mike Vella Zarb
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vaibhav Mittal wrote:you might find link useful.

That did help a bit, thanks for your input
 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler can only check for syntax, i.e. missing braces, undefined method calls or variables (typing System.Out.println()), etc. The words/symbols in the java file do not follow the established rules of what can follow what.

a run-time error happens when the code is syntactically correct, but something weird happens. For example, you ask the user to enter two values, and your code will divide 'a' by 'b'. Your code can be 100% correct, but if the user inputs 0 for the denominator, you will get an exception at runtime.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Vella Zarb wrote: I know there's an error, but when is it set off is the hard part...

practice makes man perfect
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic