[fpc-pascal] methods of an object to create others objects
Bihar Anwar
bihar_anwar at rocketmail.com
Tue Jul 6 17:10:58 CEST 2010
Michael, what do you think about the following popular nested try-except-finally construct?
try
try
...
except
...
end;
finally
...
end;
My understanding of your last statement is the above construct is superfluous. Did it what you mean? If yes, is it only true in objfpc mode?
Thanks.
----- Original Message ----
From: Michael Van Canneyt <michael at freepascal.org>
To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Sent: Tue, July 6, 2010 7:22:36 PM
Subject: Re: [fpc-pascal] methods of an object to create others objects
On Tue, 6 Jul 2010, Graeme Geldenhuys wrote:
> On 5 July 2010 23:17, Michael Van Canneyt wrote:
>>
>> I would even add to this that you need to guard for exceptions:
>>
>> A:=TSomeClass.Create;
>> try
>> // do stuff
>> finally
>> A.Free; Make sure it is freed, even in case of exception.
>> end;
>
>
> Wouldn't it be nice if we had a try..except..finally statement
> supported in FPC. All-in-one.
>
> eg:
>
> A := TSomeClass.Create;
> try
> // do stuff
> except
> // handle error
> finally
> A.Free; // it is freed, even in case of exception.
> end;
>
>
> This would save such a lot of typing and indentation.
In this particular case you don't need the finally at all.
If you catch the exception, code will execute normally after the except
block. You don't need the finally then.
Michael.
More information about the fpc-pascal
mailing list