This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes When is it a compiler error and when is it a runtime exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "When is it a compiler error and when is it a runtime exception?" Watch "When is it a compiler error and when is it a runtime exception?" New topic
Author

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

Mike Vella Zarb
Greenhorn

Joined: Dec 28, 2009
Posts: 21
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


It is a mistake to think that you can solve any major problem with just potatoes.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

I cant see anything in your question. the blind answer is www.google.com
Mike Vella Zarb
Greenhorn

Joined: Dec 28, 2009
Posts: 21
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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jun 11, 2008
Posts: 23
you might find link useful.


"Life is good"
Mike Vella Zarb
Greenhorn

Joined: Dec 28, 2009
Posts: 21
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

Joined: Dec 28, 2009
Posts: 21
Vaibhav Mittal wrote:you might find link useful.

That did help a bit, thanks for your input
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Mike Vella Zarb wrote: I know there's an error, but when is it set off is the hard part...

practice makes man perfect
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When is it a compiler error and when is it a runtime exception?
 
Similar Threads
will the code give cmpiler error......
constructor and inheritance
compile time vs. runtime error/exception
Exception
Runtime Exceptions, Do they need try-catch at all?/