[fpc-pascal] Food for thought - language string improvement
Dmitry Boyarintsev
skalogryz.lists at gmail.com
Mon Jul 10 17:28:44 CEST 2017
On Mon, Jul 10, 2017 at 11:19 AM, Sven Barth via fpc-pascal <
fpc-pascal at lists.freepascal.org> wrote:
> Though you can't use the same code block for multiple types.
>
Structured development to the rescue :)
===
program project1;
{$mode delphi}
{$RANGECHECKS on}
uses SysUtils;
function HandlingIt(const e: exception): Integer;
begin
writeln('something bad has happened:');
writeln(e.message);
Result:=0;
end;
function Catch(a,b: byte; oper: char): byte;
begin
try
if oper = '+' then Result:=a+b
else if oper = '/' then Result:=a div b;
except
on e: EDivByZero do begin
writeln('division by zero');
Result:=0;
end;
on e: EIntOverflow do Result:=HandlingIt(e);
on e: ERangeError do Result:=HandlingIt(e);
end;
end;
begin
writeln( catch (1,1,'+'));
writeln( catch (255,255,'+'));
writeln( catch (1,0,'/'));
end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170710/787a9d75/attachment.html>
More information about the fpc-pascal
mailing list