jredburn has asked for the wisdom of the Perl Monks concerning the following question:

I have a large C program into which I have added the ability to embed Perl code. Using G_EVAL, I have managed to catch any 'die' statements in the Perl code. However, when there is a syntax error, or a missing module, the entire program crashes. Is it possible to catch this sort of error and handle it in C? perlembed / perlcall didn't have anything that seemed relevant.

Replies are listed 'Best First'.
Re: Catching errors in embedded Perl
by tilly (Archbishop) on Oct 14, 2004 at 17:02 UTC
    One solution is to have the only actual embedded Perl code be a function to load more Perl code. Then syntax errors or missing modules in the additional Perl code are turned into dies that you already know how to trap.
Re: Catching errors in embedded Perl
by tall_man (Parson) on Oct 14, 2004 at 16:59 UTC
    What about running your embedded perl code through "perl -c" first and looking for "syntax OK"?

    I'm having difficulty seeing how perl code with syntax errors and missing modules would end up in an embedded application when it could be checked in advance. Are you letting users enter arbitrary perl from an input stream? If so, that's a security risk.

      Understood. However, the program itself is a large server and the Perl code consists of add-on modules written by users for themselves to add functionality. While ideally each user would run their code through 'perl -c' ahead of time, I don't want to punish them for a bug in their Perl code with a crash of the entire server that may be supporting other requests.