Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Can't call method "otherwise" without a package or object reference at

by rpelak (Sexton)
on Oct 06, 2010 at 05:05 UTC ( #863723=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Can't call method "otherwise" without a package or object reference at
in thread Can't call method "otherwise" without a package or object reference at

Okay I can confirm that otherwise is defined (I think)... I added this to the top of the sub...

try { my ($k) = 2; throw sysAssert("test assert"); } catch err with { my ($ex) = @_; print "caught by with\n"; dPrt("warn"," with $ex"); } otherwise { my ($ex) = @_; print "caught by otherwise \n"; dPrt("warn","OTHERWISE:$ex"); } die "got here";
I didn't get an error about a call to otherwise, but at the same time, neither the catch err with nor the otherwise got called. The err shouldn't have caught it, since it was intentionally a different exception type. but the otherwise should have from my understanding. instead the exception was uncaught, and simply killed execution... Which may mean I don't understand what otherwise is supposed to do... but http://search.cpan.org/~shlomif/Error-0.17016/lib/Error.pm says
otherwise BLOCK Catch any error by executing the code in BLOCK When evaluated BLOCK will be passed one argument, which will be th +e error being processed. The error will also be available in $@. Only one otherwise block may be specified per try block
So I am pretty sure it should have caught that... but I am not seeing either print statement in either block, nor the die statement. So the exception is not being caught...
thoughts?


Comment on Re^4: Can't call method "otherwise" without a package or object reference at
Select or Download Code
Re^5: Can't call method "otherwise" without a package or object reference at
by ig (Vicar) on Oct 06, 2010 at 07:17 UTC

    It looks like you're missing a semicolon between the otherwise block and the die. It should be:

    try { my ($k) = 2; throw sysAssert("test assert"); } catch err with { my ($ex) = @_; print "caught by with\n"; dPrt("warn"," with $ex"); } otherwise { my ($ex) = @_; print "caught by otherwise \n"; dPrt("warn","OTHERWISE:$ex"); }; die "got here";
      Whoops. yep. Had that in all the others, missed it on this one. But adding it didn't change the result.
        What do you get from perl -MO=Deparse,-p script.pl for the offending chunk?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-08-23 19:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls