On 02.03.2013 14:04, Xiangrong Fang wrote:
Hi,
Could anyone explain this:
Number := 123;
try
Number := Ln(0);
except
end;
WriteLn(Number);
The output is *Nan*, not 123. i.e. when exception occurs the variable is
modified anyway! So in the example below assigning MyInstance to nil
before Create does not help to ensure it is nil if an exception occurs?
Because there is no exception. If you put a "Writeln" or something into
the except block you'll see that no exception is raised. Additionally
the "ln" is a compiler intrinsic. And as you give it a constant 0 the
compiler will hardcode the "NaN" value instead of calculating it.
The safest way in this case is to put the "Number := 123" into the
"except" block (though in this specific example it wouldn't change
anything).
Regards,
Sven
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus