Lukasz Wozniak wrote:Yes, i understand that. But example 4 is the main point of my question : like you said Vijitha, compiler knows exactly what 'if(true)' is. So, in my opinion, it should be a compile error on line 19, because line is unreachable since we throw new exception. But line 19 compiles fine.
The reasoning for example 1 and 2, is different for example 3 and 4. Example 1 and 2 is explained by Vijitha above.
As for example 3 and 4, the "unreachable code" checks are disabled for "if" conditions. The reasoning is to allow for conditional code. It is common practice to have something like this...
where "debugging" is a compile time constant. So, if the checks were not disabled, and debugging is off, you can have unreachable inside the "if" block.
Henry