This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime & Compile time Error

 
Lovleen Gupta
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats the difference between runtime error and compile time error?
Is runtime error and exception and the same thing?

Please clarify.

Thanks,
Lovleen.
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a general programming concept. Most simply:

A compile-time error is a problem found at compile time.

A runtime error is anything that goes wrong at runtime -- in Java, runtime errors are usually indicated/communicated via exceptions (Throwable and family).
 
Mike Petrogeorge
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yea, compile exceptions are caught by the compiler, and runtime exceptions are caught at runtime. But for the test, you gotta know that compile time exceptions are known as checked-exceptions (extend object Exception) and run time exceptions extend RuntimeException (who also extends the Exception). Check the java 5 documentation. You will find that Throwable is the daddy object, Exception extends Throwable and is the main object. Then you have the RuntimeException. Exceptions like NullPointerException and ArithmeticException extend the RuntimeException. Hence runtime exceptions (as far as the test is concerned).
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing as a "compile exception" or "compile time exception". As Stuart said, there are "compile errors", which the compiler reports (nothing to "catch" here, as as there is no exception involved).

Runtime exception come in checked and unchecked varieties. Checked exceptions need to be treated in the code either by a try/catch block, or a "throws" clause in the method declaration. The compiler will enforce this. Unchecked exception extend java.lang.RuntimeException, and do not need to be treated in the code.
 
Gaurav Pavan Kumar Jain
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Loovelen

Runtime Errors are considered as Exceptions in java. Where Compile time errors are simply just errors which occurs due to improper Syntax.

I think it is the answer you want.

Nice question.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic