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,ee1a8b8db84c88f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!solnet.ch!solnet.ch!news-zh.switch.ch!switch.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Ada exception block does NOT work? Date: Thu, 18 Aug 2005 14:56:41 +0200 Organization: CERN - European Laboratory for Particle Physics Message-ID: References: <4301ab29$0$6989$9b4e6d93@newsread2.arcor-online.net> <54s1ed.kjh.ln@hunter.axlog.fr> NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1124369801 3113 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050724 Red Hat/1.7.10-1.1.3.1.SL3 X-Accept-Language: en-us, en In-Reply-To: <54s1ed.kjh.ln@hunter.axlog.fr> Xref: g2news1.google.com comp.lang.ada:4161 Date: 2005-08-18T14:56:41+02:00 List-Id: Jean-Pierre Rosen wrote: > There are no predefined exceptions in C++ There are. In particular, creating a new object on the free store can result in failure due to inability of the system to allocate memory. This is how you create new object on the free store: int *p1 = new int; MyType *p2 = new MyType(); etc. In case of memory allocation error, the above will result in the std::bad_alloc exception being thrown. This is predefined and standard exception in C++. > therefore things like > arithmetic overflow have undefined semantics The "therefore" part above is not correct. Since there *are* predefined exceptions in C++, dealing with arithmetic anomalies certainly was based on other, unrelated policies. Whether this is good or bad in any particular context is another issue. >> Why do you claim that Ada's exceptions are "better integrated into the >> language than in the languages that throw and catch them"? > > Every sequence of statements can have an exception handler in Ada, while > in C++/Java/C# you must add an extra level of nesting. You add the nesting if you want to handle the exception. If you don't want to handle it, you don't add the nesting. This is rather the result of having a *pair* of parentheses to denote a block, with no sensible way of extending this punctuation. In Ada, "begin" and "end" are not a closed pair and are easier to extend with any other keyword, thus making a "comb" of arbitrary length. But this is a syntax issue. I treat Ada's "begin" as having implicit "try" if there is any handler downstream. Is there anything inherently wrong in this? > This gives the > feeling that dealing with exceptions is something you just put in very > special places, while in Ada you are more inclined to considering > exceptions everywhere. But then we will drift to discuss whether it makes sense to deal with exceptions everywhere or maybe only where the actual handler has something to do. I haven't seen enough real Ada code to have any opinion what is good in the Ada context. Don't you do this: begin -- ... Some_Procedure_That_Might_Raise; -- ... end; and just let the exception (if any) travel up the chain to where there is enough context to actually *do* somethng with the exception? >> Note that those other languages can throw regular objects as >> exceptions > > This boils down to the (controversial) question of how much information > should be associated to an exception. [...] > So, you see the question is quite open... Yes, it is and I understand the concerns you mention. But I'm still not sure about the "integration with the language" issue. In what way the Ada exceptions are more integrated with the language than the C++ exceptions (or take any other language from the "throwing" family)? -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/