[fpc-pascal]exception handling

Thomas Schatzl tom_at_work at gmx.at
Wed Mar 17 13:28:36 CET 2004


Hi again,

> > spent a few moments going over the docs in the manual re: exception
> > handling. for some reason it just doesn't seem to be sinking in, as
> > nothing i've tried as of yet has managed to stop prog from crashing when
> > data in input that's of a different type than program is expecting
> > (string as opposed to integer, for example).
>
> [...]
>
> - did you include the sysutils unit?
> - afaik readln just raises runtime error which is unspecified according to
> the docs; eventually an EIOError (or similar if this does not exist)
because
> this behaviour can be turned on/off with $I+/-.
> But to be sure, you might want to catch general exceptions.
> - do the following:
>
> s: String;
> i : Integer;
> code : Word;
>
> try
>     readln(s);
>     i := StrToInt(s);
> catch
>     on EIOError ...
> end;

Obviously it should mean "on EConvertError..." here because StrToInt raises
an EConvertError when the string does not represent a valid integer.... (see
docs)
Not an EIOError, this one probably slipped in because I was talking about
catching an I/O Error in the other variants...

Sorry,
  Thomas





More information about the fpc-pascal mailing list