[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] tcp-connect doesn't correctly signal errors

From: Peter. Bex
Subject: Re: [Chicken-users] tcp-connect doesn't correctly signal errors
Date: Thu, 15 Sep 2005 10:05:49 +0200

----- Original Message -----
From: Michael Benfield <address@hidden>
Date: Thursday, September 15, 2005 7:23 am
Subject: Re: [Chicken-users] tcp-connect doesn't correctly signal errors

> Indeed. But in C, the connect function returns -1 on error, and so I
> know that the socket file descriptor won't work. In Chicken Scheme, 
> tcp-connect returns two ports that appear to be valid until I use them
> and my program is killed. I have no way of knowing that the ports 
> I've received aren't valid, and so tcp-connect is not safe to use in 
> real code (unless I want to actually try to deal with the SIGPIPE 
> signal, which I don't). tcp-connect should signal an exception. As
> it does if, for example, I do this:
> (tcp-connect "" 12345)
> Maybe I'm just missing something here but I don't think so.

The C way of checking for errors is tedious and error-prone.  How
often did you forget to check a return value and simply worked with
invalid data?

In newer languages there are exceptions: These are errors that will
crash your program unless you catch them. The idea is that you catch all errors
you expect.  If there are unforeseen problems, your program will not endlessly
try to work with false data but crash immediately, leaving a stack trace so you
can find the exact spot where the error occurred. Have a look at this:

But I agree that tcp-connect should throw the exception instead of write, 
because of
the "Rule of Repair" 
"Repair what you can — but when you must fail, fail noisily and as soon as 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]