Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Do you know where your variables are?
 
PerlMonks  

Re^6: Use of "die" in OO modules

by theguvnor (Chaplain)
on Jan 27, 2007 at 18:59 UTC ( [id://596921]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^5: Use of "die" in OO modules
in thread Use of "die" in OO modules

Are you saying that if I eval { die MyExceptionClass->new(...) }; that the $@ variable will contain the instance of MyExceptionClass? Wow. It never dawned on me that that might be the case... This changes everything!

[Jon]

Replies are listed 'Best First'.
Re^7: Use of "die" in OO modules
by adrianh (Chancellor) on Jan 28, 2007 at 16:31 UTC
    Are you saying that if I eval { die MyExceptionClass->new(...) }; that the $@ variable will contain the instance of MyExceptionClass?

    Exactly ;-) From perldoc die:

    die() can also be called with a reference argument. If this happens to be trapped within an eval(), $@ contains the reference. This behavior permits a more elaborate exception handling implementation using objects that maintain arbitrary state about the nature of the exception. Such a scheme is sometimes preferable to matching particular string values of $@ using regular expressions.

      Awesome.. I tried it and I like it!

      Now I just wish that something like this:

      catch (ThisClass $e) {...} catch (ThatClass $e) {...}
      was built into Perl!!

      [Jon]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://596921]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.