Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Where did $@ go?

by ELISHEVA (Prior)
on Mar 21, 2011 at 13:50 UTC ( #894516=note: print w/ replies, xml ) Need Help??


in reply to Where did $@ go?

an empty string for $@ that tests as true

The last time I saw such weirdness (empty string tests as true), my so called empty string contained a null character as its first character. To confirm this print out $@ with Devel::Peek::Dump (see Devel::Peek).

As for how that null got there? Anybody's guess. Exiting an eval block triggers the destructors for all data that is no longer needed. If there is an eval in one of those destructors, $@ can be easily reset. I didn't see any DESTROY subroutine in either Mail::Builder::Simple or Mail::Builder. However, Mail::Builder uses Moose which has plenty of magic and there are several other modules involved as well. Any one of them could be doing something that causes $@ to be reset.

My own preferred syntax for exception handling is

eval { ... my code here ... # eval is guaranteed to return undef if it fails # this ensures we only enter the do block (return false) # if and only if we die # Note: returns from eval NOT containing sub return 1; } or do { # save $@ because it is fragile and easily reset my $e=$@; ... my error handling code here ... };


Comment on Re: Where did $@ go?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://894516]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-08-31 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls