[Newbies] Re: error trap
Ron Teitelbaum
Ron at USMedRec.com
Wed Aug 9 19:11:40 UTC 2006
Brian,
Yes I agree it's a great suggestion, although a few changes:
Literal blocks to not parse into collections automatically.
Also the code [each value] on: ... is very interesting, so I thought I'd
spend a moment on it.
Each in this case is already a block. It doesn't look like a block so
people sometimes feel the need to encase a block in a block. This can cause
a lot of problems, when your block doesn't evaluate since aBlock value:
[aBlock] returns aBlock not the blocks value. Try this and see:
myTrueBlock := [Transcript show: 'That''s TRUE!'; cr; endEntry].
true ifTrue: [myTrueBlock]
Now try this,
true ifTrue: myTrueBlock.
Now consider this: myTrueBlock value.
So in your example:
[each] would not work since [] value returns a block each.
[each value] does work since it is really doing [] value -> each value.
But since aBlock on: do: does aBlock value, only aBlock is needed.
Only each is needed. So here is a version that works.
(OrderedCollection new
add: [10/0];
add: [2 raisedToInteger: 1/2];
add: [-5 raisedTo: 1.5]; yourself
) do: [:each | each on: Exception do: [:ex | Transcript show: ex; cr;
endEntry]].
endEntry is for Klaus!
It is a very good suggestion Brian!
Ron Teitelbaum
> -----Original Message-----
> From: beginners-bounces at lists.squeakfoundation.org [mailto:beginners-
> bounces at lists.squeakfoundation.org] On Behalf Of Klaus D. Witzel
> Sent: Wednesday, August 09, 2006 2:32 PM
> To: beginners at lists.squeakfoundation.org
> Subject: [Newbies] Re: error trap
>
> On Wed, 09 Aug 2006 19:59:41 +0200, Brian Murphy-Dye wrote:
> > Ron, another crazy possibility comes to mind when reading your
> > excellent description: making each line it's own block.
> >
> > {[10/0].
> > [2 raisedToInteger: 1/2].
> > [-5 raisedTo: 1.5]
> > } do: [:each | [each value] on: Exception do: [:ex | Transcript show:
> > ex; cr]].
>
> Excellent, Brian. Why do you still write in the beginners list ;-)
> ...
> Ah, now I can see why: Transcript endEntry is missing from the above :)
> </joke>
>
> /Klaus
>
> > Brian.
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
More information about the Beginners
mailing list