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:


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?
Of course.

--
---------------------------------------------------------
           J-P. Rosen (rosen@xxxxxxxxx)
Visit Adalog's web site at http://www.adalog.fr
.



Relevant Pages

  • Re: Silly and stupid post-condition or not ?
    ... reason for that is that access types are type-safe (in the absence of ... "All Ada features which require ... the profile and contract of a subprogram. ... it's perfectly reasonable to prove useful things about exceptions. ...
    (comp.lang.ada)
  • Re: Seeking for papers about tagged types vs access to subprograms
    ... `pragma Restrictions ` which should even ... Initially I just wanted to get ride of function returning unconstrained types and the exceptions runtime and keep only the last‑chance handler, but it appears the high level parts of the runtime depends on the exceptions support (ex. ... SPARK is often said to be used for application with time and memory bounds requirement, but I don't know any way to prove timing bounds in SPARK. ... May be there would be a hope to do something similar to what SPARK did, just with bigger consequences, re‑factoring Ada outside of Ada. ...
    (comp.lang.ada)
  • Re: [announcement] SYSAPI and SYSSVC for Windows
    ... Ada did solve this, it introduced the requeue-statement. ... User-definable assignment for all types ... An ability to specify the contract so that the semantics of the copy ... But there are also numerous problems with exceptions in Ada. ...
    (comp.lang.ada)
  • Re: Silly and stupid post-condition or not ?
    ... I don't much care why SPARK is the way it is -- it's obvious that it makes ... I want a tool that would be useful for typical Ada programs, ... going to have dispatching and access types and exceptions and tasks ... ... language", which is not a step forward for my uses. ...
    (comp.lang.ada)
  • Re: [announcement] SYSAPI and SYSSVC for Windows
    ... Ada has its own concept. ... I know no language which ... But there are also numerous problems with exceptions in Ada. ... > supporting such languages as Ada. ...
    (comp.lang.ada)