comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: Constraint Error
Date: Thu, 30 Sep 2004 00:42:28 GMT
Date: 2004-09-30T00:42:28+00:00	[thread overview]
Message-ID: <UDI6d.13481$gG4.4398@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <cjfg8e$g6i$00$1@news.t-online.com>

Rick Santa-Cruz wrote:
> 
> how can I avoid the Constraint Error, when executing the following code:

Don't violate the constraint.

>  package Messages is
>  type Message is tagged private;
>  subtype String_Txt is String(1..20);

Objects of this subtype always have exactly 20 Characters.

> 
>  function Create(Str: String) return Message;
> 
>  private
>   type Message is tagged
>    record
>     Text: String_Txt;
>    end record;
> end Messages;
> ------------------------------
> package body Messages is
>  function Create(Str: String) return Message is
>   M: Message;
>  begin
>   M.Text := Str;

If Str'Length /= 20, Constraint_Error will be raised.

>   return M;
>  end Create;
> end Messages;

-- 
Jeff Carter
"Hello! Smelly English K...niggets."
Monty Python & the Holy Grail
08




  reply	other threads:[~2004-09-30  0:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-29 23:24 Constraint Error Rick Santa-Cruz
2004-09-30  0:42 ` Jeffrey Carter [this message]
2004-09-30  0:42 ` Stephen Leake
2004-09-30  1:11 ` tmoran
2004-09-30 13:47 ` John A. S. Rowlands
  -- strict thread matches above, loose matches on Subject: below --
1999-04-07  0:00 Constraint error Nirmala Bhupathi
1999-04-07  0:00 ` Matthew Heaney
1999-04-07  0:00   ` Nirmala Bhupathi
1999-04-08  0:00     ` Matthew Heaney
1987-04-10 21:47 Constraint_Error keith
replies disabled

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