• traperrors

    From dik@21:1/5 to All on Mon May 24 09:40:46 2021
    hi -

    in turbo pascal one traps errors like this:

    {$I-}
    reset(f);
    errnum := ioresult;
    if (errnum <> 0) then HALT(errnum);
    {$I+}

    in irie pascal (http://irietools.com/) one does
    this:

    traperrors (false);
    reset(f);
    errnum := getlasterror;
    if (errnum <> 0) then HALT(errnum);
    traperrors (true) ;

    i am attempting to port irie to turbo. i cannot see
    how to write a 'traperrors' procedure in turbo
    pascal.

    i would appreciate any help. thanks.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stephen Mitchell@21:1/5 to dik on Wed May 26 07:23:09 2021
    On Monday, May 24, 2021 at 12:40:47 PM UTC-4, dik wrote:
    hi -

    in turbo pascal one traps errors like this:

    {$I-}
    reset(f);
    errnum := ioresult;
    if (errnum <> 0) then HALT(errnum);
    {$I+}

    in irie pascal (http://irietools.com/) one does
    this:

    traperrors (false);
    reset(f);
    errnum := getlasterror;
    if (errnum <> 0) then HALT(errnum);
    traperrors (true) ;

    i am attempting to port irie to turbo. i cannot see
    how to write a 'traperrors' procedure in turbo
    pascal.

    i would appreciate any help. thanks.
    You don't say what version of Turbo Pascal you're using, but the short answer is that I don't think it can be done, at least in a standard way (one that doesn't require knowledge of Turbo's internals). The most obvious approach, sadly, won't work:

    procedure traperrors(active : boolean);
    begin
    if active then
    {$I+}
    else
    {$I-};
    end;

    This will compile and run without bombing (at least under Turbo Pascal 5.5, which is what I tested it on), but the call to traperrors(true) won't actually turn error trapping back on. That's because the compiler directives are evaluated at compile-time,
    not run-time, and the last one encountered while compiling, which is {$I-} will control for the remainder of the program.

    But it shouldn't be a big deal. The Irie Programmer's Manual, though it encourages the use of traperrors(), indicates that the Irie compiler will, for compatibility, accept the {$I} forms. So if you're writing code for the Irie compiler, simply go ahead
    and use {$I-} and {$I+} instead of traperrors, and you will be able to bring the code to Turbo without having to edit it. If you're dealing with code that already uses the traperrors procedure, however, then you'll have to make the change manually, but
    that should not be difficult.

    Maybe someone else can come up with a better solution?

    Stephen Mitchell
    Alexandria, Virginia, USA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)