[Boulder.pm] How do I catch "Can't locate <module>.pm" errors at runtime

Adriano Ferreira a.r.ferreira at gmail.com
Mon Oct 19 10:23:47 PDT 2009


On Mon, Oct 19, 2009 at 3:07 PM, Janine Goldstein <janine at ucar.edu> wrote:

> Hi Boulder Perl Mongers,
>
> I have been trolling the web looking for help with a programming problem
> and I found your group. Hopefully this is a good place to ask my question.
>
>
> I have some code that uses a Perl module and I would like to catch the
> error "Can't locate <module>.pm in @INC" at runtime, give use user an
> error message telling them they need to run the code on a different
> machine, and exit gracefully.
>
> I have tried:
>
> no warnings FATAL
> eval {use <module>}; warn $@ if $@;
>


The problem here is that you are using

     eval BLOCK

rather than

     eval STRING

such as in

     eval "use <module>".

The "eval BLOCK" form compiles the BLOCK -- so this form does not catch
syntax or other compile-time errors. The "use" statement is a compile-time
statement -- so if the module is not there, it will die when compilation,
instead of  when running the "eval" as you expected.




> BEGIN {$SIG{"__WARN__"} = sub {...};
> try {use <module>;} catch {...};
>
> all to no avail. Am I messing up the syntax or is there something more
> fundamental going on?
>
> Thanks for any and all help!!!!
>
> Janine
>
> _______________________________________________
> Boulder-pm mailing list
> Boulder-pm at pm.org
> http://mail.pm.org/mailman/listinfo/boulder-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/boulder-pm/attachments/20091019/cfcf62ce/attachment.html>


More information about the Boulder-pm mailing list