[fpc-pascal] Re: how to simplify try try except end finally end?

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Fri Dec 27 19:33:16 CET 2013


Dennis Poon wrote:
>> For what it's worth, I'm ambivalent. Not because I feel that try 
>> stacks couldn't or shouldn't be simplified, but because I feel that 
>> whoever overloaded  try  for two different structures should be shot.
> 
> I don't know enough about compiler. Could you kindly elaborate on the 
> above please?

There are two distinct programming structures, with- as I understand it- 
significantly different code generation requirements. Both are 
introduced by the reserved word "try".

The first structure, which is broadly comparable with most modern 
languages, is

try
..
   raise...
..
except
..
end;

with "raise" transferring control to the exception handler.

The second structure is

try
..
finally
..
end;

and I might be wrong but I don't think there's an analogue of "raise" in 
this case.

In my own scripting stuff I've used

start
..
   stop...
..
finally
..
end;

This obviously doesn't reduce verbosity, but my own opinion is that it 
improves clarity since you won't in general encounter

try
   try
..

and then have to go to the end of the blocks to work out what's intended.

In principle it would be possible to define "start" as a macro, but I 
don't know how badly that would confuse Lazarus/Synedit highlighting and 
code folding. In practice it's completely incompatible with Delphi (and, 
as far as I know, every other Pascal variant) so is probably not a habit 
to get into.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list