Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Error Trapping

crashedcrashed Posts: 6Member
Hi all,

Can anyone help me with trapping error 106 at runtime with the readln command?

Rgds,
crashed

Comments

  • gyapeszgyapesz Posts: 19Member
    : Hi all,
    :
    : Can anyone help me with trapping error 106 at runtime with the readln command?
    :
    Hi crashed,

    excerpt from Turbo Pascal Help:

    "Read and ReadLn report this error if a numeric value read from a text file doesn't conform to the proper numeric format."

    Ergo, I suggest
    a) using (for testing/trapping only) not a numeric, but a string variable for reading data (this always works) and
    b) setting a breakpoint after reading from file this string. From the string's format You can know what's happening.

    Best regards,

    gyapesz


  • ThozzThozz Posts: 20Member
    Hi there!.

    Just try this:

    var
    x : integer;

    begin
    write('Type an integer: ');
    {$I-}
    readln(x);
    {$I+}
    if (IOResult = 0) then writeln('Ok, thanks!')
    else writeln('I have asked for an integer!!!');
    end.

    {$I-} turns off runtime error while reading from a file or from the keyboard!. If there is something bad, function IOResult results different to 0.
  • crashedcrashed Posts: 6Member
    : Hi there!.
    :
    : Just try this:
    :
    : var
    : x : integer;
    :
    : begin
    : write('Type an integer: ');
    : {$I-}
    : readln(x);
    : {$I+}
    : if (IOResult = 0) then writeln('Ok, thanks!')
    : else writeln('I have asked for an integer!!!');
    : end.
    :
    : {$I-} turns off runtime error while reading from a file or from the keyboard!. If there is something bad, function IOResult results different to 0.
    :


    Do I need to USE any library???

    Thanks for your help.
    Crashed
  • ThozzThozz Posts: 20Member
    : Do I need to USE any library???
    No!. It runs under TP7 without using any library. I think it's the same under FPC.

Sign In or Register to comment.