Re: Ada exception block does NOT work?

Maciej Sobczak a écrit :
Jean-Pierre Rosen wrote:

There are no predefined exceptions in C++

There are.
Certainly depends on which version of C++. I am happy to learn that they eventually made it, but still the language hasn't been designed with exceptions in mind.

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.
At the time where this policy was decided, there was no exceptions at all. I guess that changing this to raising exceptions would have been too incompatible.

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?
Well, in C++ you pretty well need to know precisely what code will raise which exception. That's what the syntax says; "try" means: I know that the following code may fail (and conversely, without a "try", I assume it may not fail). Ada is more oriented towards "expecting the unexpected". That's what I meant with the sentence below:

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:

    -- ...
    -- ...

and just let the exception (if any) travel up the chain to where there is enough context to actually *do* somethng with the exception?
Of course.

           J-P. Rosen (rosen@xxxxxxxxx)
Visit Adalog's web site at