comp.lang.ada
 help / color / mirror / Atom feed
From: Mats Weber <matsw@mail.com>
Subject: Re: Problem with function return
Date: 2000/04/03
Date: 2000-04-03T16:06:03+00:00	[thread overview]
Message-ID: <38E8C166.3BA83AE0@mail.com> (raw)
In-Reply-To: 8c96al$rr5$1@nnrp1.deja.com

Robert Dewar wrote:

> >    type color_kind is (nil, red, green, blue);

> This seems a bad idea to me, it will result in C-like errors
> of the caller forgetting to check for an error, yes it may
> be caught, but it is much to easy for it to get swallowed
> up, e.g. by the else clause of an if.
> 
> Much better to raise an exception. if the caller wants to handle
> it they can put an exception handler at the call site. If they
> don't want to handle it, or more likely they forget, then the
> exception gets raised and unhandled, which is often better than
> blindly carrying on!

Of course an exception is best when feasible, but I have used the Nil
technique quite often when I need the enumerated type as a discriminant
and a default value is required, as in:

type R (Color : Color_Kind := None) is
   record
      case Color is
         when None =>
            null;
         when Red =>
            ....
      end case;
   end record;




      reply	other threads:[~2000-04-03  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-02  0:00 Problem with function return Amgarp
2000-04-02  0:00 ` David Starner
2000-04-03  0:00 ` A. Logue
2000-04-02  0:00   ` Ray Blaak
2000-04-03  0:00     ` Robert Dewar
2000-04-03  0:00   ` Robert Dewar
2000-04-03  0:00     ` Mats Weber [this message]
replies disabled

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