From: Freddy <Alfred.Hilscher@t-online.de>
Subject: Re: Exceptions vs Error return values
Date: Mon, 06 Aug 2001 23:31:41 +0200
Date: 2001-08-06T23:31:41+02:00 [thread overview]
Message-ID: <3B6F0CBD.C81CB765@t-online.de> (raw)
In-Reply-To: fb75c450.0108051328.2039584c@posting.google.com
Hambut schrieb:
>
> I'm currently trying to get to grips with winsock programming. As
> part of this process I'm trying to put together a slightly higher
> level binding to the thin one provided with Gnat.
>
> The 'thin' binding provides a lot of functions returning an
> integer. The value of this integer encodes a whole range of possible
> errors. I want to replace this 'C'-esque way of doing stuff with Ada
> exceptions; my question is "What is a sensible guideline for choosing
> between exceptions and error return codes?"
In my own bindings (a port from Modula-2) I prefered return values as
- it is more effectiv
- it prevents the programmer from writing a lot of exception handlers
(for nearly every call), you would have to
catch (and handle) all IP related exception (you shouldn't use the
"others" choice)
- it's more readable
- it is sometimes not relevant what the actual returncode was (some of
the codes are not really exceptual)
This is my personal preference, others may differ.
procedure Ping (Host : STRING; RC : out Integer) is
s : Socket;
Result : Integer;
Data : STRING := " abcdef";
Buffer : STRING (1..255);
Buffer_Len : Integer;
Host_IP : IPV4;
Sender : IPV4;
Sender_Port : Integer;
begin
RC := No_Error;
Init (Result);
if Result /= No_Error then RC := Result; return; end if;
GetHostAddress (Host, Host_IP, Result);
if Result /= No_Error then RC := Result; Cleanup (Result); return;
end if;
CreateRawSocket (Protocoll_ICMP, s, Result);
if Result /= No_Error then RC := Result; Cleanup (Result); return;
end if;
Fill_Header (1, 1, Data);
SendTo (s, Data, Host_IP, 0, RC, Timeout_Immediate);
if Result /= No_Error then RC := Result; Cleanup (Result); return;
end if;
RecvFrom (s, Buffer, Buffer_Len, Sender, Sender_Port, Result,
1000);
if Result /= No_Error then RC := Result; Cleanup (Result); return;
end if;
Cleanup (Result);
if Result /= No_Error then RC := Result; end if;
end Ping;
prev parent reply other threads:[~2001-08-06 21:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-05 21:28 Exceptions vs Error return values Hambut
2001-08-05 22:30 ` tmoran
2001-08-06 12:47 ` Stephen Leake
2001-08-06 13:57 ` Ted Dennison
2001-08-06 21:31 ` Freddy [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox