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,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-05 14:28:38 PST Path: archiver1.google.com!newsfeed.google.com!postnews1.google.com!not-for-mail From: hfrumblefoot@yahoo.com (Hambut) Newsgroups: comp.lang.ada Subject: Exceptions vs Error return values Date: 5 Aug 2001 14:28:38 -0700 Organization: http://groups.google.com/ Message-ID: NNTP-Posting-Host: 62.188.137.125 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 997046918 27710 127.0.0.1 (5 Aug 2001 21:28:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 5 Aug 2001 21:28:38 GMT Xref: archiver1.google.com comp.lang.ada:11325 Date: 2001-08-05T21:28:38+00:00 List-Id: 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?" Looking at some of the error codes there are a couple that seem natural exceptions. For example when 1 Winsock hasn't been initialised by a call to WSAStartup, or when 2 Winsock detects that the network has fallen over. In both cases Winsock is not able to fulfil the service to the client (in the case of 1 because of improper use by the client, and in the case of 2 due to some external event), so the client needs to be notified in no uncertain terms that something is wrong. But there are other cases that are less obvious, for example when 1 The Winsock call returns no data, or when 2 The operation has been blocked by another windows socket operation. In both cases Winsock is still able to fulfil the services it's offering. The client may continue to use its services, but it is advisable for the client to take some kind of action. Would it be a sensible guideline to relate the use of exceptions to the severity of error (for example as described in table below)? Exception/ : Error Type Error Value : ------------:------------------------ Exception : Server package about to overwrite all memory with garbage Exception : Server package can not fulfil offered services Error Value : Server package can not fulfil called service with : provided parameters Error Value : Service results in a 'not-expected' but correct result : (e.g. returning a null host name) I've had a delve through Barnes, and through the Ada95 style guide, and neither really helped to clear my mind on this point. Any thoughts gratefully received... Cheers, Hambut. p.s. I suppose you could almost do both; a child package providing 'exceptions' and another child providing 'error values'. That way the client could choose the most appropriate mechanism for the application. Would this be useful, or just overkill?