Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Using Perl Exception Class

by Perllace (Acolyte)
on Apr 20, 2011 at 08:51 UTC ( #900294=perlquestion: print w/ replies, xml ) Need Help??
Perllace has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, This is my perl problem I have a script something like
$object1 = $ABC->Find('test1'); #Then I want to call a subroutine called CheckResult in #Report.pm Report->CheckResult($object,”Finding the value”); #In another case I want to report if a particular command #was execute +d, so I do something like this.. Report->CheckResult($ABC->Command(100,100),”Performing the command”);
Now in Report.pm #Report.pm
sub CheckResult { my ($result,$information) = @_; #Now, I need something like this .. If( $result->isa(‘MyException’)) { #Some code to create the report } }
How do I use exception class and how to check if an exception is raised,and if so perform the task necessary..?? Thanks, Perllace

Replies are listed 'Best First'.
Re: Using Perl Exception Class
by Corion (Pope) on Apr 20, 2011 at 08:58 UTC

    You don't tell us what concept of "structured exception" you are using. If you are using one of the modules on CPAN, like Exception::Class or Exception, have you looked at the documentation?

    If you think implementing your own mechanism makes sense, take a look at eval and/or Try::Tiny.

    As an aside, the code you posted does not compile. Perl does not like the kinds of quotes you use:

    ”Performing the command” # should be "Performing the command" ‘MyException’ # should be 'MyException'
      Hi Corion I think Exception::Class will suit my need.. how do i use it??
Re: Using Perl Exception Class
by moritz (Cardinal) on Apr 20, 2011 at 10:04 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2016-06-30 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (403 votes). Check out past polls.