comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison<dennison@telepath.com>
Subject: Re: Exceptions vs Error return values
Date: Mon, 06 Aug 2001 13:57:40 GMT
Date: 2001-08-06T13:57:40+00:00	[thread overview]
Message-ID: <onxb7.320$NJ6.619@www.newsranger.com> (raw)
In-Reply-To: uzo9dgxtf.fsf@gsfc.nasa.gov

In article <uzo9dgxtf.fsf@gsfc.nasa.gov>, 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



  reply	other threads:[~2001-08-06 13:57 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 [this message]
2001-08-06 21:31 ` Freddy
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox