If the result is different from what you thought it would be, let us know what you were expecting, and we'll try to sort it out. [ August 04, 2007: Message edited by: Ulf Dittmer ]
Dude if take a look at this code, both are logically same, but this works fine.
Maybe so, but the compiler is not smart enough to know that. In the first case, it does know that the exception will be thrown, and hence, the code after the try-finally block is not reachable. In the second case, it is just an arithmetic expression, that is not checked for runtime errors during compile time.
Dude, If the complier knows then why isn't it complaining at compile time.If you analyze the following snippets,
Snippet 1: ----------- int x = 10/0; // This code block is for sure to throw an error. So issues should be resolved at compile time.
Snippet 2: ----------- int x,y int z = x/y; // The value of Y cannot be determined till run time.So it make sense to throw a runtime exception, but not in the former case.
If the compiler sits quiet then it should do the same for
throw new RuntimeException();
For the complete code please refer to starting posts.
If the complier knows then why isn't it complaining at compile time.If you analyze the following snippets,
Because the compiler doesn't know. It knows that it is a literal zero, and it knows that it will divide them, but there is no check at compile time to determine whether it may throw an exception at runtime. This may change in the future, as the compiler improves, but currently, it doesn't make such a check.