Design question

Hans-Martin Mosner hm.mosner at cityweb.de
Mon Sep 3 19:40:25 UTC 2001


danielv at netvision.net.il wrote:
> 
> I've been looking at and modifying the RefactoringBrowser and the Squeak
> Parser, and I've been puzzled by something.
> 
> Look at this bit of code -
> 
>         address _ NetNameResolver addressForName: serverName timeout: 15.
>         address = nil ifTrue: [
> ->              self error: 'Could not find host address'].
> 
>         "connect the socket"
>         self connectTo: address port: 110.
>         (self waitForConnectionUntil: POPSocket standardDeadline) ifFalse: [
>                 self close.
> ->              self reportToObservers: 'failed to connect to server'.
> ->              ^false ].
> 
[...some stuff omitted...]
> So -
> What are the Pros and Cons for exceptions and other callback mechanisms?
> 
> Daniel

I *feel* like exceptions would be the right thing to use here.
First, the NetNameResolver should either return a resolved host address,
or it should raise one of these exceptions: 'host not found', 'query
timed out', or 'host has no address' (yes that's possible with DNS-based lookups).
Second, either the #connectTo: or #waitForConnectionUntil: method should
either return with the connected socket, or it should signal a
'connection rejected' or 'timed out' exception.
Of course, other exceptions might exist for both of these cases...

Then the client might choose to catch and handle these exceptions, or it
might just let its caller handle them. So the simplest version looks
like this:

	address := NetNameResolver addressForName: serverName timeout: 15.
	self connectTo: address port: 110.
	self waitForConnectionUntil: POPSocket standardDeadline.
	"After this, the socket is connected"

What do people think?

Cheers,
Hans-Martin





More information about the Squeak-dev mailing list