in reply to Can I catch exceptions
What you are seeing is not an exception or an error, it is a warning. A subtle difference perhaps, but the eval and die technique will not trap warnings.
What you need to do is to temporarily modify __WARN__ so that instead of the default, which is to print out the warning, it does what you want. You say that you want to catch the "error" and generate your own message. You could do something like this:
Note that you MUST enclose this in a block (such as putting it in it's own sub like this) otherwise you will be confused by any other warnings later printing your own message.sub my_comparison{ @_ == 2 or die "Incorrect number of args to my_comparison"; local $SIG{__WARN__} = sub { print "Tried to test a non-number with +==\n" }; local $^W = 1; $_[0] == $_[1]; }
-- iakobski
|
|---|