Brian Szymanski via RT wrote:
Show quoted text> Ok, got the book in front of me now. The relevant (penultimate)
> paragraph on page 297 reads:
> Refactoring in this way is usually a highly recommended practice, but in
> this case it has the potential to introduce a subtle bug. The problem is
> that the $EVAL_ERROR exception variable (a.k.a. $@) is a global
> variable. So if fail_if_incorrigible() happens to throw -- and then
> internally catch -- some other exception during its execution, that
> nested exception will overwrite $EVAL_ERROR.
Looking at the example given directly above, I can see the possibility of making an exception for an eval block that ends with a return statement.
However, let us pretend that the contents of the eval block do not contain a return statement. Then, the test of the Exception::Class object is not valid due the the reasons that this policy was created; whatever fail_if_incorrigible() does is not relevant to the discussion here.
What he discusses here is losing the value of $EVAL_ERROR /after/ the eval has finished. What this policy is concerned about is what happens to the value of $EVAL_ERROR /during/ the execution of the eval. The else part of if statement in his example is not correct, because it assumes that $EVAL_ERROR contains an object. Given the type of thing that this policy is looking for, the value of $EVAL_ERROR might be undef or a string.
The documentation could include a pointer to this part of the book, but it's not what this policy is looking for.
Really what needs to happen is for there to be a new policy that requires you to save the value of $EVAL_ERROR prior to using it, which would be a reference to this part of the book.