comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Exceptions vs Error return values
Date: 06 Aug 2001 08:47:08 -0400
Date: 2001-08-06T12:47:15+00:00	[thread overview]
Message-ID: <uzo9dgxtf.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: fb75c450.0108051328.2039584c@posting.google.com

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.

> <snip>
> 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



  parent reply	other threads:[~2001-08-06 12:47 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 [this message]
2001-08-06 13:57   ` Ted Dennison
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