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

patspiper patspiper at gmail.com
Sat Mar 2 18:43:49 CET 2013


On 02/03/13 19:34, waldo kitty wrote:
> On 3/2/2013 08:25, Xiangrong Fang wrote:
>> I guess there is really a bug, see the following:
>> ==============================
>>    f := 123;
>>    try
>>      f := ln(0);
>>    except
>>    end;
>>    //WriteLn(f);
>>    //{
>>    if f = 123 then
>>      WriteLn('f=123, not modified')
>>    else
>>      WriteLn('f is modified to:', f);
>>    //}
>> ===============================
>>
>> If I just WriteLn(f), it output Nan, I think there is some magic 
>> happening here.
>>
>> If I try to use if-then on f, then I get:
>>
>> An unhandled exception occurred at $000000000040028C :
>> EDivByZero : Division by zero
>>    $000000000040028C line 18 of project1.lpr
>
> i am unable to reproduce this...
>
> Lazarus 1.1 r39940 FPC 2.6.0 i386-win32-win32/win64
>
>
> i started a new Simple Program project and pasted your above code into 
> it...
>
> C:\Documents and Settings\nil>LOCALS~1\Temp\project1
> f=123, not modified
>
>
> program Project1;
>
> var
>   f : extended;
>
> begin
>   f := 123;
>     try
>       f := ln(0);
>     except
>     end;
>     //WriteLn(f);
>     //{
>     if f = 123 then
>       WriteLn('f=123, not modified')
>     else
>       WriteLn('f is modified to:', f);
>     //}
> end.
>
>
> so i started a new Program project and again...
>
> C:\Documents and Settings\nil>LOCALS~1\Temp\project1
> f=123, not modified
>
>
> program Project1;
>
> {$mode objfpc}{$H+}
>
> uses
>   {$IFDEF UNIX}{$IFDEF UseCThreads}
>   cthreads,
>   {$ENDIF}{$ENDIF}
>   Classes
>   { you can add units after this };
>
> var
>   f : extended;
>
> begin
>   f := 123;
>     try
>       f := ln(0);
>     except
>     end;
>     //WriteLn(f);
>     //{
>     if f = 123 then
>       WriteLn('f=123, not modified')
>     else
>       WriteLn('f is modified to:', f);
>     //}
> end.
>
>
> what am i missing??
Probably 
http://wiki.freepascal.org/Multiplatform_Programming_Guide#Gtk2_and_masking_FPU_exceptions

Stephano




More information about the Lazarus mailing list