On 8 Jun, 08:35, "Dmitry A. Kazakov" <mail...@[EMAIL PROTECTED]
>
wrote:
> On Sun, 08 Jun 2008 09:47:30 +0300, Niklas Holsti wrote:
> > The solution is just to add one more "begin..end" block, enclosing
> > the "declare .. begin .. end", and handle the exceptions in this
> > outer "begin..end" block. Or handle the exceptions in the
> > subprogram's "begin..end" block and nest the "declare..begin..end"
> > within the subprograms "begin..end".
>
> > That said, I admit that I, too, have made this mistake once or
> > twice. But not lately.
>
> If exceptions were contracted such, quite nasty, errors could be
detected
> at compile time.
>
> > I wonder if it would be a good idea for Ada to allow an exception
> > handler also in the "declare" part, as follows:
>
> > =A0 =A0 -- NOT Ada!
> > =A0 =A0 declare <some variables>
> > =A0 =A0 exception <handle exceptions raised in the declarations>
> > =A0 =A0 begin <some statements>
> > =A0 =A0 exception <handle exceptions raised in the statements>
> > =A0 =A0 end;
>
> > Of course, in this proposal the declaration-exception handler would
> > not have access to the declared variables.
>
> But then, for regularity sake, you would need to add exception handling
to=
> all declarative parts:
>
> package A is
> =A0 =A0 <some declarations>
> exception
> =A0 =A0 <handling elaboration problems of A, HOW?> =A0(:-))
> end A;
Admittedly the range of options is pretty limited if exception
handlers where to be added to package specs but you could log an
indication in a package local variable, set a default or re-raise the
exception.
I rather like the idea...that forced nesting just to catch an
exception is quite ugly and dare I day, goes against Ada's "easy to
read and therefore maintain" mantra...
Cheers
-- Martin


|