[fpc-pascal]exception handling
kractor
baron.kractor at cogeco.ca
Wed Mar 17 14:18:15 CET 2004
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 - fpc-pascal at lists.freepascal.org
>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 ... :)
More information about the fpc-pascal
mailing list