File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiler vs. Runtime Error

 
juliane gross
Ranch Hand
Posts: 161
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything like a "Rule of Thumb" or
does anyone know of an easier way to learn
which errors would result in a Runtime Error,
and which would result in a Compiler Error?
For example, using the dot-operator on null
results in a Runtime Error; why wouldn't want
the compiler take care of it?
Thanx for answering,

Juliane
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler will report any errors it can find, but it's not all that smart. It never knows the value that any variable contains, so it will always allow you to dereference a variable (as long as the compiler is sure the variable has been initialized to some value.)
Similarly, it can check whether a type cast is plausible, but it can't check whether the cast will definitely succeed or not, so casts fail at runtime unless the compiler can prove that two types definitely can't be interconverted.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic