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 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!news2.google.com!proxad.net!news.cs.univ-paris8.fr!informatik.uni-bremen.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: handling null pointers/records to functions Date: Sat, 21 Aug 2004 17:11:13 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <41274733@dnews.tpgi.com.au> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1093108273 10963 134.91.1.34 (21 Aug 2004 17:11:13 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Sat, 21 Aug 2004 17:11:13 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: g2news1.google.com comp.lang.ada:2914 Date: 2004-08-21T17:11:13+00:00 List-Id: Jim Rogers wrote: :>quasar wrote: : You ask about returning some kind of null object. I suggest what : you might consider here is defining some value of the Data member : to indicate no data. This approach avoids exception handling but : is easier to get wrong at the calling context. The calling : context must compare all return values with the "no data" value : before proceeding. Failure to do so will propogate bad data : throughout the rest of the program. Maybe you can also add a default value parameter to the function that is returned when the Node_Ptr_Type value is null. function Data_Part (Node_Ptr : Node_Ptr_Type; default_value: Data_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"); return default_value; end if; end Data_Part; : The use of exceptions is really much more reliable in this case. Have you, quasar, wanted a precondition of node_ptr /= null? In this case the precondition will not be satisfied by a null access. Therefore raising an exception seems an adequate solution. -- Georg