Subject: | Unhelpfully half-works if TryCatch loaded in a different package |
Create two files 'a' and 'X.pm' with these contents:
==> a <==
use lib '.';
use X;
try {} catch {}
==> X.pm <==
package X;
use TryCatch;
1;
Now 'perl a' will appear to work correctly. Even though you forgot to
'use TryCatch' in that file, no error is raised from the try {} catch {}
construct.
However, change the code in 'a' slightly, to
use lib '.';
use X;
try {} catch ($err) {}
Now you get a syntax error. This is puzzling for the programmer, who
had code which appeared to be working but gives an odd error when
changing 'catch {}' to 'catch ($err) {}'.
It would be better for any use of try and catch to fail cleanly if the
TryCatch module has not been loaded in the current package, although it
might have been loaded elsewhere by some other package.