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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fd8f3d2ebf73a4b7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-21 09:09:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!dispose.news.demon.net!demon!btnet-peer0!btnet!news5-gui.server.ntli.net!ntli.net!news6-win.server.ntlworld.com.POSTED!not-for-mail From: "chris.danx" Newsgroups: comp.lang.ada References: Subject: Re: Whether to raise exception or End_of_List function MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: <68RK7.3295$AQ3.467408@news6-win.server.ntlworld.com> Date: Wed, 21 Nov 2001 17:04:38 -0000 NNTP-Posting-Host: 213.104.128.9 X-Complaints-To: abuse@ntlworld.com X-Trace: news6-win.server.ntlworld.com 1006362242 213.104.128.9 (Wed, 21 Nov 2001 17:04:02 GMT) NNTP-Posting-Date: Wed, 21 Nov 2001 17:04:02 GMT Organization: ntlworld News Service Xref: archiver1.google.com comp.lang.ada:16801 Date: 2001-11-21T17:04:38+00:00 List-Id: "Preben Randhol" wrote in message news:slrn9vnh96.55u.randhol+abuse@kiuk0156.chembio.ntnu.no... > Hi > > I have made a simple double linked list that I use in the application I > develop. Before somebody suggest I use some other libraries I want to > say that I made this double linked list to learn Ada 95 and get aware of > different problems/aspects of implementing this, so at least for this > application I want to keep it for now. > > The list code can be viewed here: http://www.pvv.org/~randhol/Ada95/List/ > Note that the code is still rough, I haven't removed some debugging > functions/procedures etc... > > I put this into a package: > > package Examine_List is > new Double_Linked_List (Data_Type => Natural); > > Main_Examine : Examine_List.List_Type := Examine_List.New_List; > > And use the Main_Examine. So far it has worked nicely, but now I came to > that at one place (at least) in my application I have to go from the > current position of the iterator until the end of the list. I cannot > know the current position of the list iterator so I cannot use a > for-loop. If I want to use a while loop however there are the problem of > knowing when the end of the list is reached. I guess I can make a > function End_of_List (which must also work if one try to backwards in > the list) or I can just raise an exception when the user tries to > step off the list. > > My question is which is the better solution; Exception or a End_of_List > function and which would have fewer side effects? Have both! i.e. an End_Of_List function for when you need to know when you've reached the end of a list, and an exception for when you fall of the list and attempt to use it. I have a similar problem with a recent assignment, and I found both to be helpful (exceptions are for getting the bugs out, and knowing where they are (although not all bugs are detectable by exceptions)). An exception will be generated anyway if your iterator attempts to use a null valued access type (assuming that's how the implementation works), but you may want your own exception -- it can be helpful sometimes. Chris