> Dear Experts,
> I have the following lines in my codes to test a string:
[quoted text clipped - 15 lines]
> Regards,
> Serguei.
Provided you have something more than a comment in the catch clause then
no legal implementation of Java could optimise the lines away.
Mark Thornton
> Dear Experts,
> I have the following lines in my codes to test a string:
[quoted text clipped - 8 lines]
> The variable "value" is not used anymore, so a clever compiler may
> remove the try block.
But even though value may not be used, the action of Integer.parseInt
may have some side effects. Suppose str is set to be "dw23f~~"? The
value of str would have to be known (or limited in some form) and the
semantics of Integer.parseInt would have to be guaranteed to not throw
an exception.
One can argue that the call related to the assignment of the value
should be optimized as well, but some assignments for unused variables
may be purposeful in effect.
I can't see how the optimization would avoid violating the JLS in these
circumstances without requiring serious in-depth analysis of the code
and also keeping binary compatibility.
As a final note: a try-catch statement adds very little overhead when
not called, and the assignment is equally negligible in effect.
> In my Java environment the compiler does not "optimize" these lines
> and everything works OK.
The Sun Java compiler does not optimize because optimized code hampers
the ability of the JIT optimizer to optimize the code (although variable
propagation analysis probably doesn't have an impact).

Signature
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth