Marcus Holland-Moritz <[EMAIL PROTECTED]> writes: >> >> try/catch (i.e. eval {} in perl speak) is a little tricky to do from pure XS. >> I usually call (a trivial) perl sub and use G_EVAL on the call. > >There's a way to do try/catch (under certain circumstances) in XS. >If you use a recent ppport.h, it's even portable back to perl 5.003: > > XCPT_TRY_START > { > risky_stuff(); > } > XCPT_TRY_END > > XCPT_CATCH > { > /* cleanup things here */ > > XCPT_RETHROW; > }
Thanks, I had forgotten that had been put into ppport.h This is almost certainly better than G_EVAL-ing a perl sub. But this and call scheme are probably overkill if all you want to do is cleanup on exit from scope. I now recall that you can callsv(an_xsub,G_EVAL) which avoids having to have a trivial perl function. > >The only limitation is that you _have to_ rethrow the exception in >the catch block, i.e. you cannot catch an exception and just ignore >it. This is documented in the perlguts and perlapi manpages. And as I wanted to ignore (some) cases that explains why I have never used it and hence forgot about it.