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 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 05:51:14 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Exceptions vs Error return values Date: 06 Aug 2001 08:47:08 -0400 Organization: NASA Goddard Space Flight Center Message-ID: References: NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 997102035 25438 128.183.220.71 (6 Aug 2001 12:47:15 GMT) X-Complaints-To: dscoggin@cne-odin.gsfc.nasa.gov NNTP-Posting-Date: 6 Aug 2001 12:47:15 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Xref: archiver1.google.com comp.lang.ada:11347 Date: 2001-08-06T12:47:15+00:00 List-Id: hfrumblefoot@yahoo.com (Hambut) writes: > 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. A laudable goal. > 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?" I always raise an exception whenever the function cannot do what the caller expected. On the other hand, I don't define a different exception for every error. There are two mechanisms to encode different errors; either use Ada.Exceptions.Raise_Exception with a message string, or provide a function that returns an error code. In the case of Windows stuff, raising Windows_Error, and allowing the user to get the Windows error code, is sufficient. > > 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? Overkill. -- -- Stephe