I just changed the docs to replace payload with message here. It's not a
language bug, however.

Here's the change on github:

   
https://github.com/perl6/doc/commit/fb5d341036afe387f0ead0b76e09aef75205dcaf


On 28/02/2019 21:54, ToddAndMargo via perl6-users wrote:
>
>> On 28/02/2019 12:46, ToddAndMargo via perl6-users wrote:
>>> Hi All,
>>>
>>> https://docs.perl6.org/language/exceptions#Catching_exceptions
>>>
>>> I am trying to place .payload into a variable `my $Payload = .payload;`
>>>
>>>
>>> CATCH {
>>>     # Reference:
>>> https://docs.perl6.org/language/exceptions#Catching_exceptions
>>>     my $NotifyStr;
>>>     my $Payload = .payload;
>>>
>>>     default {
>>>        # $*ERR.say: .payload;
>>>        PrintRedErr( "$Payload\n" );
>>>        $NotifyStr = $Payload;
>>>        for .backtrace.reverse {
>>>           next if .file.starts-with('SETTING::');
>>>           next unless .subname;
>>>           # $*ERR.say: "  in block {.subname} at {.file} line {.line}";
>>>           PrintRedErr( "  in block {.subname} at {.file} line
>>> {.line}\n" );
>>>        }
>>>     }
>>>     RunNoShell( "notify-send -u critical -t 0 -i \"$AlarmJpg\" \"CATCH
>>> Trap \" \"$NotifyStr\"" );
>>> }
>>>
>>>
>>> But keep pulling the following error:
>>>
>>>       No such method 'payload' for invocant of type
>>>       'X::TypeCheck::Assignment' in block <unit>
>>>       at ./GetUpdates.pl6 line 60
>>>
>>> Line 60 is `my $Payload = .payload;`
>>>
>>> What am I doing wrong?
>>>
>>> Many thanks,
>>> -T
>
> On 2/28/19 7:27 AM, Timo Paulssen wrote:> As you can see from the
> routine page for "payload":
> >
> >      https://docs.perl6.org/routine/payload
> >
> > it only exists on X::AdHoc, which if you follow the link "from
> X::AdHoc"
> > explains:
> >
> >      X::AdHoc is the type into which objects are wrapped if they are
> > thrown as exceptions, but don't inherit from Exception.
> >
> > In your case you have a proper exception, i.e. the
> X::TypeCheck::Assignment
> >
> > In this case you'll probably want .message instead. .message on
> X::AdHoc
> > will call .Str on the payload and return that, which is basically the
> > same thing you wanted to do with the payload with
> > PrintRedErr("$Payload\n") anyway. On top of that, every Exception
> object
> > implements message.
> >
> > Hope that helps!
> >    - Timo
> >
>
> Hi Timo,
>
> That did the trick.  Thank you!
>
> Did I just trip across a bug?
>
> -T

Reply via email to