From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,83575a3c82229268 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-06 14:41:02 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: Freddy Newsgroups: comp.lang.ada Subject: Re: Exceptions vs Error return values Date: Mon, 06 Aug 2001 23:31:41 +0200 Organization: T-Online Message-ID: <3B6F0CBD.C81CB765@t-online.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.t-online.com 997133769 00 25276 9vcRS4vGSGAOIm 010806 21:36:09 X-Complaints-To: abuse@t-online.com X-Sender: 320001779794-0001@t-dialin.net X-Mailer: Mozilla 4.75 [de] (WinNT; U) X-Accept-Language: de Xref: archiver1.google.com comp.lang.ada:11418 Date: 2001-08-06T23:31:41+02:00 List-Id: 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;