[Lazarus] Assignment on exception (was Re: exception handling in constructor)

Michael Van Canneyt michael at freepascal.org
Sat Mar 2 14:44:19 CET 2013



On Sat, 2 Mar 2013, Sven Barth wrote:

> 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.

Hah, I had not thought of this. Indeed, assembler shows you are right :-)

Michael.




More information about the Lazarus mailing list