[fpc-pascal] Food for thought - language string improvement

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Mon Jul 10 15:53:02 CEST 2017


On Mon, Jul 10, 2017 at 3:46 PM, Graeme Geldenhuys
<mailinglists at geldenhuys.co.uk> wrote:
> Then lastly, you can even add a finally block in there too (Java calls this
> try-with-resources).

No, that's not what try-with-resources is.

This is try-with-resources:
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

Any object which implements the interface AutoClosable is auto-closed
in the try, regardless of an exception happening or not.

Pascal is a little different, since it has destructors, so I guess in
Pascal we could auto-free objects in a hypotetical try-with-resources
in Pascal. Something like:

try ( stringList := TStringList.Create;
 otherObj := TSomeOtherClass.Create; )
  code here
except
  exception block, optional
end;

And any object in the () section would be auto-freed, auto-checking if
it was already created or not.

-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list