This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to differentiate between compile time errors and runtime errors ?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im having tough time in understanding questions related to compile time and runtime error. Can you please shed light on this topic as how to proceed in this regard? i have two code listings shown below:

Code Listing 1 :


Code Listing 2:





the compiler gives error in Code Listing 2 as to variable j might not have been initialized. Can you please tell me what the compiler thinks when it encounters code listing 1 and 2. And also the generalized version of the problem relating to compile time error and runtime exception. ??
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Gurpreet,

Welcome to JR.

Well, there is a quick pointer. In code listing 1, the compiler will always execute the initialization for i before evaluating the condition.
So it compiles fine. In case-2, initialization of j is conditionally dependent on the outer loop. The compiler is not sure whether the outer
loop will even run or not, so it in such a scenario, it suspects as its dependent on outer loop, it is not necessary that j will initialize that's
why it will give the compile time error.

HTH,
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic