[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: catch & throw (ATTN: Dave Ungar & co.)
There's already a similar capability defined in Self. What you call "catch"
we call "exit" and "exitValue" (depending on whether nil or a particular value
is returned from the catch block). We don't create any special throwBlock
objects to send "throw:" to, instead using normal blocks to send "value:" to
to exit the catch block. So instead of writing
[|:errorTag|
message: errorTag
] catch.
message: errorTag = (
errorTag throw: 'oops!'.
'this code never happens!' print.
).
as you did, you would write
[|:errorTag|
message: errorTag
] exitValue. "or exit"
message: errorTag = (
errorTag value: 'oops!'.
'this code never happens!' print.
).
BTW, you can't make the "block" data slot in your throw block object private,
since the "block:" message in the "with:" method of throw blocks would not have
access; the sending method holder (in this case, the prototypical throwBlock)
is not an ancestor of the receiver of the "block:" message, so private slots
are invisible. So just make the "block" data slot public (or unspecified) to
get your example to work.
-- Craig Chambers