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=0.6 required=5.0 tests=BAYES_00,TO_NO_BRKTS_FROM_MSSP autolearn=no 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 06:57:50 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!newsranger.com!www.newsranger.com!not-for-mail Newsgroups: comp.lang.ada From: Ted Dennison References: Subject: Re: Exceptions vs Error return values Message-ID: X-Abuse-Info: When contacting newsranger.com regarding abuse please X-Abuse-Info: forward the entire news article including headers or X-Abuse-Info: else we will not be able to process your request X-Complaints-To: abuse@newsranger.com NNTP-Posting-Date: Mon, 06 Aug 2001 09:57:40 EDT Organization: http://www.newsranger.com Date: Mon, 06 Aug 2001 13:57:40 GMT Xref: archiver1.google.com comp.lang.ada:11351 Date: 2001-08-06T13:57:40+00:00 List-Id: In article , Stephen Leake says... > >hfrumblefoot@yahoo.com (Hambut) writes: > >> 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. If there is another call that can be made to get the exact error code, I'd usually just provide a binding to that. Otherwise, I'm with Steven in that I don't like to create tons of different exceptions. I ususally just create one named "Error" (eg: Sockets.Error). I also used to tack any extra info onto the exception message. The problem I found with doing that is that there are often arbitrary limits on the maximum length of that message. What I prefer to do these days is define an error message string (as Ada.Strings.Unbounded), and provide that to the user. --- T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html home email - mailto:dennison@telepath.com