comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@comcast.net>
Subject: Re: handling null pointers/records to functions
Date: Sun, 22 Aug 2004 04:12:33 GMT
Date: 2004-08-22T04:12:33+00:00	[thread overview]
Message-ID: <R2VVc.165762$8_6.61119@attbi_s04> (raw)
In-Reply-To: 41274733@dnews.tpgi.com.au

Of course the answer depends on the behavior you want.
Right off hand, you may find it worthwhile to look into the package
Ada.Exceptions.

With Ada.Exceptions you can associate a message with an exception occurance.
So you you might make the code read something like:

  Null_Ptr_Exception : Exception;

function Data_Part (Node_Ptr : Node_Ptr_Type ) return Data_Type is

begin
  if node_ptr = null then
    Raise_Exception( Null_Ptr_Exception'Identity,
                               "Node passed to FUNCTION DATA_PART is
null" );
  end if;
  return Node_Ptr.Data;
end Data_Part;

Whatever you decide to do, you should document the behavior in the package
spec.

Steve
(The Duck)

"quasar" <quasar@nospam.com> wrote in message
news:41274733@dnews.tpgi.com.au...
> Hi , I was wondering what is the best way to handle null records/pointers
> passed to functions with a return type that is generic?
>
> for example in this snippet of code node_ptr_type is a record holding a
> single data value of type Data_Type
>
> function Data_Part (Node_Ptr : Node_Ptr_Type ) return Data_Type is
> begin
>     if node_ptr /= null then
>         return Node_Ptr.Data;
>     else
>         Put_Line("Node passed to FUNCTION DATA_PART is null");
>         {(**)at this point i do not know what to do... do I terminate the
> program, do I return some form of null object}
>     end if;
> end Data_Part;
>
> What is the most recommended way to handle this? Point (**) has got me
> stuck.
>
> Thanks any help would be great
> quasar
>
>





      parent reply	other threads:[~2004-08-22  4:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-21 12:59 handling null pointers/records to functions quasar
2004-08-21 13:55 ` Jim Rogers
2004-08-21 17:11   ` Georg Bauhaus
2004-08-21 19:54 ` Jeffrey Carter
2004-08-22  4:12 ` Steve [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