diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1999-03-24 05:33:28 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-03-24 05:33:28 +0000 |
commit | 52531d10235032d7a6699893866618bfd041b167 (patch) | |
tree | 3b9a018b83a56b014db25c60b793852116261a28 | |
parent | 399388f477781ca816dab1ea03623ab6ca5c7aa7 (diff) | |
download | perl-52531d10235032d7a6699893866618bfd041b167.tar.gz |
document OO exceptions (based on a suggestion by Andreas Koenig
<andreas.koenig@anima.de>)
p4raw-id: //depot/perl@3138
-rw-r--r-- | pod/perlfunc.pod | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 87f94f86c0..64f5aa4362 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -965,6 +965,27 @@ This is useful for propagating exceptions: If C<$@> is empty then the string C<"Died"> is used. +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 arbitary state about the nature of the exception. Such a scheme +is sometimes preferable to matching particular string values of $@ using +regular expressions. Here's an example: + + eval { ... ; die Some::Module::Exception->new( FOO => "bar" ) }; + if ($@) { + if (ref($@) && UNIVERSAL::isa($@,"Some::Module::Exception")) { + # handle Some::Module::Exception + } + else { + # handle all other possible exceptions + } + } + +Since perl will stringify uncaught exception messages before displaying +them, you may want to overload stringification operations on such custom +exception objects. See L<overload> for details about that. + You can arrange for a callback to be run just before the C<die()> does its deed, by setting the C<$SIG{__DIE__}> hook. The associated handler will be called with the error text and can change the error message, if |