Dirk Laurie on Wed, 06 Apr 2011 23:00:22 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Trapping errors in library mode |
On Wed, Apr 06, 2011 at 12:07:40PM +0200, Dirk Laurie wrote: > When calling the Pari library from C, I don't want my program > to exit when I do something silly like dividing by zero. and on Wed, 6 Apr 2011 13:36:04 +0200, Bill Allombert replied: > I suppose you are using PARI 2.3. In that case, the proper way is to set > INIT_JMPm and to call setjmp(GP_DATA->env) somewhere in your code to > initialize GP_DATA->env. In case of an error, PARI will do > longjmp(GP_DATA->env). I'm calling Pari via C from Lua, and did it this way: if (1 && setjmp(GP_DATA->env)) luaL_argerror(L,k,"Pari error"); This works, of course after putting into my program this line: #include <pari/paripriv.h> The error message is now very satisfactory: > pari("1/0") *** division by zero stdin:1: bad argument #2 to 'pari' (Pari error) Question though: will this still work in PARI 2.4, or must I then use the new method? Thanks! Dirk