Thomas Schatzl wrote:

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


_______________________________________________ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal



thank you kindly, this worked perfectly. to be honest, the thought of reading the data initially as a string and then using a conversion to trap the error hadn't even crossed my mind ... :)

_______________________________________________
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to