Exception Handling in perl
perl, perl-module
Solution
What happens if an eval block returns false?
That false value is returned by `eval`.
Why is that required?
It's not required.
my $foo = eval { foo() };
is perfectly fine if you're ok with `$foo` being undef on exception.
What you've seen is
if (!eval { foo(); 1 }) {
...
}
The code is returning true to let the `if` know the `eval` succeeded. `eval` will return false on exception.
Problem
I have seen a 1 appear at the end of eval blocks for exception handling in perl. Why is that required? What happens if an eval block returns false? Is this required even if we dont use $@ directly but some library from CPAN to do exception handling?