Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by ikegami (Patriarch)
on Oct 05, 2010 at 23:16 UTC ( [id://863704]=note: print w/replies, xml ) Need Help??


in reply to Can't call method "otherwise" without a package or object reference at

The error comes from something like this:
$ perl -e'$x="1"; $x->otherwise' Can't call method "otherwise" without a package or object reference at + -e line 1.

You don't appear to show any method calls to otherwise, unless something ends up being treated as an indirect method call.

$ perl -e'$x="1"; otherwise $x' Can't call method "otherwise" without a package or object reference at + -e line 1.

That would indicate otherwise isn't found as a sub.

$ perl -le'sub otherwise { print "foo" } $x="1"; otherwise $x' foo

Make sure you properly imported otherwise from whatever module provides it.

Replies are listed 'Best First'.
Re^2: Can't call method "otherwise" without a package or object reference at
by rpelak (Sexton) on Oct 06, 2010 at 00:19 UTC
    The model Error.pm is the standard module that defines the try, catch and all that. The err comes from a module of my own...
    package err; use da qw(/.*/); use dbg qw(/.*/); use base qw(Error); use overload ('""' => 'stringify'); sub new { prtDbgSubInfo(); my ($pkg,$text) = @_; my @args = (); local $Error::Depth = $Error::Depth + 1; local $Error::Debug = 1; # Enables storing of stacktrace my ($this) = $pkg->SUPER::new(-text => $text, @args); my ($stack) = $this->stacktrace; $stack =~ s#$text #$text\n\t#; #adds a newline after the text and before the first at ... my ($preMsg) = "\n--Error--"; $this->{-text} = "$preMsg\n$stack"; return($this); }
    And the other try / catch blocks work in the same sub, so the stuff is defined. It has to be something about this particular use of it... like a simple syntax error (I checked for the semi-colon on the end) or the a unique exception coming from inside, but I thought the otherwise should handle any exception type...
      Like I said earlier, make sure you properly import otherwise.
        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?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-19 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found