• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compile time vs runtime error???

 
Shashank Sharma
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey can anybody please explain me how do i figure the error gonna be compile time or runtime (obj 5.2)
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually the exam tests to see if you recognize checked exceptions that lead to compile time errors and runtime exceptions that lead to runtime errors.

Any exception that extends from the Exception class is a checked exception.
Any exception that extends from the RuntimeException is a runtime exception.

With more practice you should be able to differentiate between the two
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15443
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What John writes about is the difference between checked and unchecked exceptions; that is not the same as runtime vs. compile time errors.

Compile time errors are errors in your source code, that the compiler will give an error message about. Syntax errors and other errors in your source code are compile time errors.

Runtime errors are errors that happen later, when you run your program.
 
Shashank Sharma
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
isnt there any fix rule that what makes error to be thrown at run time or at compile time..like NoSuchMethod is thown at compile time..
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be comming in a little late on the discussion, but I hope this contrubution adds to the discussion.

I have a little set of mock exam questions on this subject that tries to drive home when something won't compile, when an Exception will get thrown, and when a RuntimeException might get thrown. I put the mock exam questions in a new JavaRanch thread so as not to hijack this one:

Mock SCJP 6.0 Exam Questions on Execptions vs. Compile Errors vs. Just Good Code!

You can see the original posting at my blog if you're interested.

-Cameron McKenzie
[ July 21, 2008: Message edited by: Cameron Wallace McKenzie ]
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15443
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shashank Sharma:
like NoSuchMethod is thown at compile time..

No, it isn't. Exceptions are never thrown at compile time. And NoSuchMethodError is an exception that could happen at runtime.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic