I would like to be able to output a custom error message to STDERR if one of my modules cannot be found.
From what I understand if I import the module with the use command the lack of the module will be discovered prior to my script being executed which poses a significant problem to achieving the result that I am looking for.
Basically what I am looking for is a Perl equivalent of catching the ImportError exception in Python.
To catch an exception in Perl you should use the
eval
operator. If the code passed toeval
dies, then the error message is put into$@
instead for you to use however you like.It would look something like this
output
You can use an
@INC
hook to do this: