in reply to Re: Re: Error module
in thread Error module
Can you refer me to the list of built-in exception I can throw/catch and how can I define a new exception (if possible) and throw/catch it.An exception is just anything that calls die with an object, since that is the native perl equivalent of other languages' throw. As for defining new exceptions, it's really just a matter of defining catch and throw methods and calling die with an object in throw. Although even this isn't necessary, but it will keep it in line with current syntax and behaviour of exceptions in the Error module. It would also be a good idea to inherit from either Error or Error::Simple to make your life much simpler.
Here's an example of a new exception
{ package KaPow; @ISA = 'Error::Simple'; sub throw { warn "Holy thrown exceptions Batman!\n"; ## must die with object die KaPow->new($_[1]); } } use Error ':try'; try { throw KaPow("The Riddler strikes again!"); } catch KaPow with { warn "this just in - $_[0]"; }; __output__ Holy thrown exceptions batman! this just in - The Riddler strikes again! at pmsopw_284549.pl line 9.
_________
broquaint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Error module
by hotshot (Prior) on Aug 18, 2003 at 16:22 UTC | |
by dragonchild (Archbishop) on Aug 18, 2003 at 17:07 UTC | |
by hotshot (Prior) on Aug 19, 2003 at 05:40 UTC | |
by dragonchild (Archbishop) on Aug 19, 2003 at 12:47 UTC | |
by hotshot (Prior) on Aug 19, 2003 at 15:37 UTC | |
| |
by particle (Vicar) on Aug 19, 2003 at 13:17 UTC |