From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,19c9b8adc049bc94 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!wns13feed!worldnet.att.net!attbi_s04.POSTED!53ab2750!not-for-mail From: "Steve" Newsgroups: comp.lang.ada References: <41274733@dnews.tpgi.com.au> Subject: Re: handling null pointers/records to functions X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Message-ID: NNTP-Posting-Host: 24.21.42.251 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s04 1093147953 24.21.42.251 (Sun, 22 Aug 2004 04:12:33 GMT) NNTP-Posting-Date: Sun, 22 Aug 2004 04:12:33 GMT Organization: Comcast Online Date: Sun, 22 Aug 2004 04:12:33 GMT Xref: g2news1.google.com comp.lang.ada:2917 Date: 2004-08-22T04:12:33+00:00 List-Id: 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" 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 > >