in reply to Propagating errors in C code to Perl

As betterworld said: you can just croak() from C and it'll throw an exception in the calling perl code. This, or returning undef/false, is almost always what you want to do.

You can set $! from C, but you should probably only do so under very limited circumstances. $! is tied directly to the C macro errno which is almost exclusively used for IO errors. Look it up. Note that errno is a number.

  • Comment on Re: Propagating errors in C code to Perl

Replies are listed 'Best First'.
Re^2: Propagating errors in C code to Perl
by missingthepoint (Friar) on Sep 06, 2008 at 07:08 UTC

    Thanks, betterworld and Joost.

    Right now to return undef I'm saying:

    return (SV *) &PL_sv_undef;

    and to return false I'm saying:

    return newSViv(0);

    are these correct? Again, is there a better way to do that?


    email: perl -e 'print reverse map { chr( ord($_)-1 ) } split //, "\x0bufo/hojsfufqAofc";'

        Thanks Joost. I'm happy - I have no further questions :)


        email: perl -e 'print reverse map { chr( ord($_)-1 ) } split //, "\x0bufo/hojsfufqAofc";'