what is Exception>>#return:?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

what is Exception>>#return:?

Chris Muller-3
What is the difference between:

[ "something" ]
    on: Error
    do: [ : err | err return: nil ]

and:

[ "something" ]
    on: Error
    do: [ : err | nil ]

?

Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: what is Exception>>#return:?

Levente Uzonyi-2
There's no difference in your example. #return: is useful if your error
handler code is not in argument block of #on:do:. E.g.:

handler := [ :anError |
  anError messageText = 'boo' ifTrue: [
  anError return: 'It was boo.' ].
  "We only reach this point if the message was not 'boo'"
  'Not boo.' ].

{
[ self error: 'boo' ]
  on: Error
  do: [ :err | handler value: err ].
[ self error: 'foo' ]
  on: Error
  do: [ :err | handler value: err ] }


Levente

On Wed, 20 Nov 2013, Chris Muller wrote:

> What is the difference between:
>
> [ "something" ]
>    on: Error
>    do: [ : err | err return: nil ]
>
> and:
>
> [ "something" ]
>    on: Error
>    do: [ : err | nil ]
>
> ?
>
> Thanks.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: what is Exception>>#return:?

Alejandro F. Reimondo
In reply to this post by Chris Muller-3
Hi Chris,

>    do: [ : err | err return: nil ]

 #on:do: send will return the result of sending
 #return: message to the object that is named
 "err" in the argument context...
 incase that message succeded to return... ;-)

>    do: [ : err | nil ]

is granted to return nil by "black box magic" of exceptions
 mechanism; and there is no way to change that
 without modifying the method.

cheers,
Ale.


----- Original Message -----
From: "Chris Muller" <[hidden email]>
To: "squeak dev" <[hidden email]>
Sent: Wednesday, November 20, 2013 10:59 PM
Subject: [squeak-dev] what is Exception>>#return:?


> What is the difference between:
>
> [ "something" ]
>    on: Error
>    do: [ : err | err return: nil ]
>
> and:
>
> [ "something" ]
>    on: Error
>    do: [ : err | nil ]
>
> ?
>
> Thanks.
>
>