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

DeAndre Carroll deandre at deandrecarroll.com
Mon Oct 19 10:22:35 PDT 2009


The thing to remember here is that 'use' is a compile time directive. It 
is shorthand for the following:

BEGIN {
    require YourModule;
    YourModule->import(LIST);
}

You could wrap the require and import steps in an eval {} and exit 
gracefully given an error (found in $@).

Hope this helps.


Janine Goldstein 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 $@;
> 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
>
>



More information about the Boulder-pm mailing list