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=0.2 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00, XPRIO_SHORT_SUBJ autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,78b2880bc7e78e39 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-16 14:13:22 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!hub.org!hub.org!fr.clara.net!heighliner.fr.clara.net!grolier!isdnet!psinet-france!psiuk-f4!psiuk-p4!uknet!psiuk-n!news.pace.co.uk!nh.pace.co.uk!not-for-mail From: "Marin David Condic" Newsgroups: comp.lang.ada Subject: Re: RISC Date: Fri, 16 Mar 2001 15:31:21 -0500 Organization: Posted on a server owned by Pace Micro Technology plc Message-ID: <98tt7g$88h$1@nh.pace.co.uk> References: NNTP-Posting-Host: 136.170.200.133 X-Trace: nh.pace.co.uk 984774704 8465 136.170.200.133 (16 Mar 2001 20:31:44 GMT) X-Complaints-To: newsmaster@pace.co.uk NNTP-Posting-Date: 16 Mar 2001 20:31:44 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Xref: supernews.google.com comp.lang.ada:5778 Date: 2001-03-16T20:31:44+00:00 List-Id: No question is stupid if you don't know the answer. There is no reason you *can't* raise an exception in a function. ("Throw" is the C++ terminology - "Raise" is the Ada terminology) There are conditions under which a function will generate an exception on its own even if you don't explicitly raise one. (Example: Hit the end of a function without returning a result. This will raise "Program_Error" - if I remember correctly.) The question "Is it good practice to raise exceptions in functions?" is fair. The answer is: "It Depends..." If you encounter a condition that is truly "exceptional" and/or it represents some sort of erroneous condition, then raising an exception is fair to do. Example: You write a function for which some combination of parameters makes no sense or leaves the function undefined. Go ahead and raise an exception. If you encounter some sort of normal, expected condition and use an exception for some sort of transfer of control, this is generally considered impolite and/or bad form. Example: You design a function to raise an exception to accomplish a loop exit when you hit the terminal condition for the loop. When to raise an exception will also depend on the nature of your system. If the system encounters an error is it proper for the program to stop running? If not, then you may not want to raise the exception - or at least guarantee you have a handler for all exceptions. Again, "It Depends." Its hard to come up with absolute rules since it often requires subjective, artistic judgements. Just keep in mind that the intention is to have a mechanism that deals with *errors* - not anticipated conditions that can be accommodated with some sort of "normal" processing. MDC -- Marin David Condic Senior Software Engineer Pace Micro Technology Americas www.pacemicro.com Enabling the digital revolution e-Mail: marin.condic@pacemicro.com Web: http://www.mcondic.com/ "chris.danx" wrote in message news:Cous6.1406$lC5.401322@news2-win.server.ntlworld.com... > Maybe i'm being stupid, please feel free to inform me if this is so, but > i'll ask anyway. > > I know functions are allowed to throw exceptions in Ada. What i want to > know is acceptable practice? I use exceptions with procedures, no problem, > but someone -- can't remember who exactly, it was ages ago -- suggested it's > bad practice! What do you think? If i remember correctly i think this > related to C++, or something, so maybe it's irrelevant to Ada. > > Just curious, > Chris Campbell > >