Jeff on Fri, 26 Nov 2010 21:35:57 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Question regarding error()


PARI users,

Iâve started using PARI for class, and although I like it, it has its
quirks.  Can you help with this?

In a file:

errmsg = ""  \\ last error message
errno  = 0   \\ last error indicator

errget() = error( errmsg )  \\ Problem with this - once error() is called,
errno and errmsg are kill()ed.

errset( msg ) =
{
    errmsg = concat( "        ", msg );
    errno  = 1;
}
...

In another file:

LJ(m,n) =
{
    if( n < 1  ||  !bitand(n,1),
        errset( "LJ(m,n): 2nd parameter must be a positive odd integer." );
        errget();
        return()
    );
... this function continues

So, you might be able to tell that Iâm trying to implement some rudimentary
error handling.  Letâs say I comment out errget() in LJ().  errset() does
what I expect, and if I call errget() from the GP shell it does what I
expect.  Now letâs uncomment errget() in LJ().  It seems to work correctly,
but then errno and errmsg are toast and have type t_POL.  Huh?  Just how
does that make any sense?  Oh, and hereâs something else, one of the
"quirks" I mentioned above: in LJ() I once called errset( "\n        "
"LJ(m..." but moved the "\n        " to concat() in errset(), but I had to
get rid of the \n to get the same effect.  It seems an implicit newline was
inserted.  I've seen this elsewhere while using print1()s, and that's
baffling.

Jeff Tomsak