comp.lang.ada
 help / color / mirror / Atom feed
* Forcing Exception Handling
@ 2011-02-28 17:27 iloAda
  2011-02-28 17:32 ` Simon Clubley
                   ` (5 more replies)
  0 siblings, 6 replies; 26+ messages in thread
From: iloAda @ 2011-02-28 17:27 UTC (permalink / raw)


Hello everybody,

I was wondering if there is a way in Ada to force exception handling.
For instance, if there is a call to a function that may raise an
exception, force the caller to handle that exception.
I was wondering if there is a compile time pragma that will isntruct
the compiler to force the handling of exceptions!!

Thanks guys

Elie



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 17:27 Forcing Exception Handling iloAda
@ 2011-02-28 17:32 ` Simon Clubley
  2011-02-28 18:33   ` onox
  2011-02-28 18:34   ` Vinzent Hoefler
  2011-02-28 20:20 ` Florian Weimer
                   ` (4 subsequent siblings)
  5 siblings, 2 replies; 26+ messages in thread
From: Simon Clubley @ 2011-02-28 17:32 UTC (permalink / raw)


On 2011-02-28, iloAda <egzgheib@gmail.com> wrote:
> Hello everybody,
>
> I was wondering if there is a way in Ada to force exception handling.
> For instance, if there is a call to a function that may raise an
> exception, force the caller to handle that exception.

What's wrong with the raise statement ?

(Or have I not understood what it is you are after ?)

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 17:32 ` Simon Clubley
@ 2011-02-28 18:33   ` onox
  2011-02-28 19:10     ` Simon Clubley
  2011-02-28 18:34   ` Vinzent Hoefler
  1 sibling, 1 reply; 26+ messages in thread
From: onox @ 2011-02-28 18:33 UTC (permalink / raw)


On Feb 28, 6:32 pm, Simon Clubley <clubley@remove_me.eisner.decus.org-
Earth.UFP> wrote:
> On 2011-02-28, iloAda <egzgh...@gmail.com> wrote:
>
> > Hello everybody,
>
> > I was wondering if there is a way in Ada to force exception handling.
> > For instance, if there is a call to a function that may raise an
> > exception, force the caller to handle that exception.
>
> What's wrong with the raise statement ?
>
> (Or have I not understood what it is you are after ?)
>
> Simon.
>
> --
> Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
> Microsoft: Bringing you 1980s technology to a 21st century world

I think he means that certain exceptions must be catched somewhere,
like Java does.



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 17:32 ` Simon Clubley
  2011-02-28 18:33   ` onox
@ 2011-02-28 18:34   ` Vinzent Hoefler
  1 sibling, 0 replies; 26+ messages in thread
From: Vinzent Hoefler @ 2011-02-28 18:34 UTC (permalink / raw)


Simon Clubley wrote:

>> I was wondering if there is a way in Ada to force exception handling.
>> For instance, if there is a call to a function that may raise an
>> exception, force the caller to handle that exception.
>
> What's wrong with the raise statement ?

He wants the "exception" statement forced, I suppose.

And no, there is currently no such thing in Ada, if only because there's
no way of telling the compiler which subroutine may raise an (user-defined)
exception. Or, IOW, there is no "throws" statement as there is in Java.


Vinzent.

-- 
A C program is like a fast dance on a newly waxed dance floor by people carrying
razors.
    --  Waldi Ravens



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 18:33   ` onox
@ 2011-02-28 19:10     ` Simon Clubley
  0 siblings, 0 replies; 26+ messages in thread
From: Simon Clubley @ 2011-02-28 19:10 UTC (permalink / raw)


On 2011-02-28, onox <denkpadje@gmail.com> wrote:
> On Feb 28, 6:32�pm, Simon Clubley <clubley@remove_me.eisner.decus.org-
> Earth.UFP> wrote:
>> On 2011-02-28, iloAda <egzgh...@gmail.com> wrote:
>> > I was wondering if there is a way in Ada to force exception handling.
>> > For instance, if there is a call to a function that may raise an
>> > exception, force the caller to handle that exception.
>>
>> What's wrong with the raise statement ?
>>
>> (Or have I not understood what it is you are after ?)
>>
>
> I think he means that certain exceptions must be catched somewhere,
> like Java does.

I see - I wasn't thinking in Java mode. :-)

Given that, the only thing I could think of was that the OP was looking
for a way for application logic to raise a exception, but that seemed
really basic, hence my question about if I had not understood the question.

Thanks for the feedback,

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 17:27 Forcing Exception Handling iloAda
  2011-02-28 17:32 ` Simon Clubley
@ 2011-02-28 20:20 ` Florian Weimer
  2011-02-28 20:35 ` Ludovic Brenta
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 26+ messages in thread
From: Florian Weimer @ 2011-02-28 20:20 UTC (permalink / raw)


* iloAda:

> I was wondering if there is a way in Ada to force exception handling.
> For instance, if there is a call to a function that may raise an
> exception, force the caller to handle that exception.

I suppose you woud use out parameters for this purpose in Ada.  Those
can be used to carry secondary or exceptional results.



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 17:27 Forcing Exception Handling iloAda
  2011-02-28 17:32 ` Simon Clubley
  2011-02-28 20:20 ` Florian Weimer
@ 2011-02-28 20:35 ` Ludovic Brenta
  2011-03-01  3:54   ` Randy Brukardt
  2011-02-28 20:38 ` Georg Bauhaus
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 26+ messages in thread
From: Ludovic Brenta @ 2011-02-28 20:35 UTC (permalink / raw)


iloAda writes:
> Hello everybody,
>
> I was wondering if there is a way in Ada to force exception handling.
> For instance, if there is a call to a function that may raise an
> exception, force the caller to handle that exception.
> I was wondering if there is a compile time pragma that will isntruct
> the compiler to force the handling of exceptions!!

I think the Ada Rapporteur Group considered the idea and rejected it.  I
seem to remember they had good reasons but I forgot which they were.
Maybe the first was that pretty much any statement can raise
Storage_Error, and that Program_Error can be raised during elaboration,
when there is no exception handler in place yet.

-- 
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 17:27 Forcing Exception Handling iloAda
                   ` (2 preceding siblings ...)
  2011-02-28 20:35 ` Ludovic Brenta
@ 2011-02-28 20:38 ` Georg Bauhaus
  2011-03-01  0:19   ` Shark8
  2011-03-01  2:08 ` Hoàng Đình Long
  2011-03-02 13:39 ` ytomino
  5 siblings, 1 reply; 26+ messages in thread
From: Georg Bauhaus @ 2011-02-28 20:38 UTC (permalink / raw)


On 2/28/11 6:27 PM, iloAda wrote:
> Hello everybody,
>
> I was wondering if there is a way in Ada to force exception handling.
> For instance, if there is a call to a function that may raise an
> exception, force the caller to handle that exception.
> I was wondering if there is a compile time pragma that will isntruct
> the compiler to force the handling of exceptions!!

IIRC, the new aspect specifications of Ada 2012 can be
used to specify that some exception might be raised.
Not sure, though.

(Given that the feature is controversial in Java,
not everyone might want them for this...)



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 20:38 ` Georg Bauhaus
@ 2011-03-01  0:19   ` Shark8
  2011-03-01  8:56     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 26+ messages in thread
From: Shark8 @ 2011-03-01  0:19 UTC (permalink / raw)


On Feb 28, 1:38 pm, Georg Bauhaus <rm-host.bauh...@maps.futureapps.de>
wrote:
> On 2/28/11 6:27 PM, iloAda wrote:
>
> > Hello everybody,
>
> > I was wondering if there is a way in Ada to force exception handling.
> > For instance, if there is a call to a function that may raise an
> > exception, force the caller to handle that exception.
> > I was wondering if there is a compile time pragma that will isntruct
> > the compiler to force the handling of exceptions!!
>
> IIRC, the new aspect specifications of Ada 2012 can be
> used to specify that some exception might be raised.
> Not sure, though.
>
> (Given that the feature is controversial in Java,
> not everyone might want them for this...)

I'm honestly not sure this would be a good idea...
In fact, given that Ada doesn't have an "exception hierarchy" like
Delphi does it may be a horrendous idea: There is no way to catch all
exceptions because there is no way to catch a  all exceptions of a
certain type (i.e. Storage_Error'Class) which is caused by the lack of
some root-type "Exception_Root."



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 17:27 Forcing Exception Handling iloAda
                   ` (3 preceding siblings ...)
  2011-02-28 20:38 ` Georg Bauhaus
@ 2011-03-01  2:08 ` Hoàng Đình Long
  2011-03-02 13:39 ` ytomino
  5 siblings, 0 replies; 26+ messages in thread
From: Hoàng Đình Long @ 2011-03-01  2:08 UTC (permalink / raw)


On Mar 1, 12:27 am, iloAda <egzgh...@gmail.com> wrote:
> Hello everybody,
>
> I was wondering if there is a way in Ada to force exception handling.
> For instance, if there is a call to a function that may raise an
> exception, force the caller to handle that exception.
> I was wondering if there is a compile time pragma that will isntruct
> the compiler to force the handling of exceptions!!
>
> Thanks guys
>
> Elie

In fact, no Java compiler can force you to handle an exception.

If you don't want to catch an exception, just throw it again. No
compiler can force you to catch that exception if you don't want to (I
am talking about Java).



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 20:35 ` Ludovic Brenta
@ 2011-03-01  3:54   ` Randy Brukardt
  2011-03-01  8:34     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 26+ messages in thread
From: Randy Brukardt @ 2011-03-01  3:54 UTC (permalink / raw)


"Ludovic Brenta" <ludovic@ludovic-brenta.org> wrote in message 
news:87y64zucco.fsf@ludovic-brenta.org...
> iloAda writes:
>> Hello everybody,
>>
>> I was wondering if there is a way in Ada to force exception handling.
>> For instance, if there is a call to a function that may raise an
>> exception, force the caller to handle that exception.
>> I was wondering if there is a compile time pragma that will isntruct
>> the compiler to force the handling of exceptions!!
>
> I think the Ada Rapporteur Group considered the idea and rejected it.  I
> seem to remember they had good reasons but I forgot which they were.
> Maybe the first was that pretty much any statement can raise
> Storage_Error, and that Program_Error can be raised during elaboration,
> when there is no exception handler in place yet.

I think it is more of a case of being unable to come to consensus than 
"rejecting" it. (Same effect, ultimately.) Some people feel that Java's 
version doesn't work very well in practice, leaving to too many "when 
Some_Exception => null" handlers rather than consideration of why the 
exceptions are being propagated. That seems like bad software management to 
me. In any case, any such "contracts" in Ada would have to be optional (for 
compatibility reasons), and that might actually help reduce the problems.

We had such a discussion just a few weeks ago (not yet filed, so I can't 
point you at it), but in any case there won't be anything in Ada 2012 (we're 
very close to freezing that version, nothing significant can be added at 
this point).

                            Randy.







^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  3:54   ` Randy Brukardt
@ 2011-03-01  8:34     ` Dmitry A. Kazakov
  2011-03-02  0:00       ` Randy Brukardt
  0 siblings, 1 reply; 26+ messages in thread
From: Dmitry A. Kazakov @ 2011-03-01  8:34 UTC (permalink / raw)


On Mon, 28 Feb 2011 21:54:08 -0600, Randy Brukardt wrote:

> I think it is more of a case of being unable to come to consensus than 
> "rejecting" it. (Same effect, ultimately.) Some people feel that Java's 
> version doesn't work very well in practice, leaving to too many "when 
> Some_Exception => null" handlers rather than consideration of why the 
> exceptions are being propagated.

I never understood this. Why Some_Exception is not added to the contract
instead? The rule is simple, if you don't know how to handle it, then
don't.

> That seems like bad software management to 
> me. In any case, any such "contracts" in Ada would have to be optional (for 
> compatibility reasons), and that might actually help reduce the problems.

Unless Storage_Error and Program_Error made manageable contracted
exceptions would have only limited use.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  0:19   ` Shark8
@ 2011-03-01  8:56     ` Dmitry A. Kazakov
  2011-03-01  9:34       ` iloAda
                         ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Dmitry A. Kazakov @ 2011-03-01  8:56 UTC (permalink / raw)


On Mon, 28 Feb 2011 16:19:22 -0800 (PST), Shark8 wrote:

> In fact, given that Ada doesn't have an "exception hierarchy" like
> Delphi does it may be a horrendous idea: There is no way to catch all
> exceptions because there is no way to catch a  all exceptions of a
> certain type (i.e. Storage_Error'Class) which is caused by the lack of
> some root-type "Exception_Root."

It is a question. Since exceptions are used in case-like clauses, more
natural where a model of a discrete type. In order to have constructs like:

   when Numeric_Exception'First..Numeric_Exception'Last =>

BTW, it shows the importance of extensible enumeration types, because
exceptions should be that kind of type.

When exceptions are bunch of types like in C++ you would loose the above.

Also consider this:

   declare
      Foo : exception:
   begin
      ...
      raise Foo;
   end;  -- Foo propagates out its scope!!

Unless Ada would have upward closures, that cannot work when Foo is a type.
I hope everybody agrees that upward closures should not be introduced.

A possibility to handle this is exception promotion, e.g. Foo to
Program_Error, when Foo gets finalized.

BTW, contracted exception would solve this problem by making such programs
illegal: each block would have an implicit contract not to propagate local
exceptions.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  8:56     ` Dmitry A. Kazakov
@ 2011-03-01  9:34       ` iloAda
  2011-03-01  9:47         ` Vinzent Hoefler
                           ` (4 more replies)
  2011-03-01 15:23       ` Shark8
  2011-03-02  0:02       ` Randy Brukardt
  2 siblings, 5 replies; 26+ messages in thread
From: iloAda @ 2011-03-01  9:34 UTC (permalink / raw)


On Mar 1, 9:56 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Mon, 28 Feb 2011 16:19:22 -0800 (PST), Shark8 wrote:
> > In fact, given that Ada doesn't have an "exception hierarchy" like
> > Delphi does it may be a horrendous idea: There is no way to catch all
> > exceptions because there is no way to catch a  all exceptions of a
> > certain type (i.e. Storage_Error'Class) which is caused by the lack of
> > some root-type "Exception_Root."
>
> It is a question. Since exceptions are used in case-like clauses, more
> natural where a model of a discrete type. In order to have constructs like:
>
>    when Numeric_Exception'First..Numeric_Exception'Last =>
>
> BTW, it shows the importance of extensible enumeration types, because
> exceptions should be that kind of type.
>
> When exceptions are bunch of types like in C++ you would loose the above.
>
> Also consider this:
>
>    declare
>       Foo : exception:
>    begin
>       ...
>       raise Foo;
>    end;  -- Foo propagates out its scope!!
>
> Unless Ada would have upward closures, that cannot work when Foo is a type.
> I hope everybody agrees that upward closures should not be introduced.
>
> A possibility to handle this is exception promotion, e.g. Foo to
> Program_Error, when Foo gets finalized.
>
> BTW, contracted exception would solve this problem by making such programs
> illegal: each block would have an implicit contract not to propagate local
> exceptions.
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de

Mmmmmm...That's what I was fearing!!
Actually the idea behind my question was that I'm working on a real
time system, and as u know, we can't afford to a let a real time
system crash because of an unhandled exception. Since I use some other
libraries in my system (that weren't written by myself or anybody else
I know) that will raise exceptions, I wanted to be forced to handle
them. I was imagining that it could be done with some kind of a
compiler pragma that will force the current package to handle all
exception that may be raised, but as u guys pointed out, the compiler
might not be able to know which procedure raises an exceptions (by
contrast java requires the addition of the "throws" instruction which
tells the compiler what's gonna happen)
One solution might be to just put the following code everywhere (even
though I don't like this):

exception
 When others =>
     --  Do something that will allow the system to keep on running

have u guys done something like that before?

thanks



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  9:34       ` iloAda
@ 2011-03-01  9:47         ` Vinzent Hoefler
  2011-03-01  9:51         ` Dmitry A. Kazakov
                           ` (3 subsequent siblings)
  4 siblings, 0 replies; 26+ messages in thread
From: Vinzent Hoefler @ 2011-03-01  9:47 UTC (permalink / raw)


iloAda wrote:

> Actually the idea behind my question was that I'm working on a real
> time system, and as u know, we can't afford to a let a real time
> system crash because of an unhandled exception. Since I use some other
> libraries in my system (that weren't written by myself or anybody else
> I know) that will raise exceptions, I wanted to be forced to handle
> them.

Better not to let them raised at all. I know, this may not be easy,
but it's the most reliable solution.

> One solution might be to just put the following code everywhere (even
> though I don't like this):
>
> exception
>  When others =>
>      --  Do something that will allow the system to keep on running

This is dangerous. Especially when doing it "everywhere". Ignoring errors
has never been a good idea, especially for the unexpected ones.

> have u guys done something like that before?

Occasionally, yes. At the outermost task level to log the exception
that caused the system to crash. If you do that inside a loop, you
might be able to restart the affected task from there.

But if you have more than one task and they interact with each other,
fault recovery like that gets quite complex, because then things like
data consistency within the whole system may be at risk. And you don't
want that to happen.


Vinzent.

-- 
A C program is like a fast dance on a newly waxed dance floor by people carrying
razors.
   --  Waldi Ravens



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  9:34       ` iloAda
  2011-03-01  9:47         ` Vinzent Hoefler
@ 2011-03-01  9:51         ` Dmitry A. Kazakov
  2011-03-01 10:07           ` iloAda
  2011-03-01 13:27         ` Mark Lorenzen
                           ` (2 subsequent siblings)
  4 siblings, 1 reply; 26+ messages in thread
From: Dmitry A. Kazakov @ 2011-03-01  9:51 UTC (permalink / raw)


On Tue, 1 Mar 2011 01:34:02 -0800 (PST), iloAda wrote:

> Mmmmmm...That's what I was fearing!!
> Actually the idea behind my question was that I'm working on a real
> time system, and as u know, we can't afford to a let a real time
> system crash because of an unhandled exception.

So long it crashes in real time everything is OK! (:-)) You meant rather
mission-critical system, I guess.

> Since I use some other
> libraries in my system (that weren't written by myself or anybody else
> I know) that will raise exceptions, I wanted to be forced to handle
> them.

You should use some static analysis tool for that. E.g. SPARK.

> exception
>  When others =>
>      --  Do something that will allow the system to keep on running

That is of course meaningless, because you don't know WHAT happened in
order to determine the SOMETHING to be done.

> have u guys done something like that before?

No, because see above. The most close thing is:

  when Error : others =>
      Trace ("Fatal:" & Ada.Exceptions.Exception_Information (Error));
+/-  raise;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  9:51         ` Dmitry A. Kazakov
@ 2011-03-01 10:07           ` iloAda
  0 siblings, 0 replies; 26+ messages in thread
From: iloAda @ 2011-03-01 10:07 UTC (permalink / raw)


On Mar 1, 10:51 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Tue, 1 Mar 2011 01:34:02 -0800 (PST), iloAda wrote:
> > Mmmmmm...That's what I was fearing!!
> > Actually the idea behind my question was that I'm working on a real
> > time system, and as u know, we can't afford to a let a real time
> > system crash because of an unhandled exception.
>
> So long it crashes in real time everything is OK! (:-)) You meant rather
> mission-critical system, I guess.
>
> > Since I use some other
> > libraries in my system (that weren't written by myself or anybody else
> > I know) that will raise exceptions, I wanted to be forced to handle
> > them.
>
> You should use some static analysis tool for that. E.g. SPARK.
>
> > exception
> >  When others =>
> >      --  Do something that will allow the system to keep on running
>
> That is of course meaningless, because you don't know WHAT happened in
> order to determine the SOMETHING to be done.
>
> > have u guys done something like that before?
>
> No, because see above. The most close thing is:
>
>   when Error : others =>
>       Trace ("Fatal:" & Ada.Exceptions.Exception_Information (Error));
> +/-  raise;
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de

Ok, thanks a lot guys!!

Elie



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  9:34       ` iloAda
  2011-03-01  9:47         ` Vinzent Hoefler
  2011-03-01  9:51         ` Dmitry A. Kazakov
@ 2011-03-01 13:27         ` Mark Lorenzen
  2011-03-01 16:11         ` J-P. Rosen
  2011-03-02  0:11         ` Randy Brukardt
  4 siblings, 0 replies; 26+ messages in thread
From: Mark Lorenzen @ 2011-03-01 13:27 UTC (permalink / raw)


On 1 Mar., 10:34, iloAda <egzgh...@gmail.com> wrote:
> Mmmmmm...That's what I was fearing!!
> Actually the idea behind my question was that I'm working on a real
> time system, and as u know, we can't afford to a let a real time
> system crash because of an unhandled exception. Since I use some other

If you cannot afford a crash, then you should make sure that
exceptions do not occur in the first place, i.e. use SPARK as others
have mentioned.

> exception
>  When others =>
>      --  Do something that will allow the system to keep on running
>
> have u guys done something like that before?

I'm currently working on a system where we can afford that the program
crashes, but we will use the above "when others" construct to catch
all possible exceptions (pre-defined and user-defined) on the outer-
most level and then simply dump the exception trace to memory (a bit
like Dmitry's example) for later (off-line) analysis after a reboot
that doesn't whipe that specific part of memory.

We will use the addr2line utility to translate the addresses of the
exception trace into file names and line numbers. You must compile
your executable *with* debug information in order to perform the (off-
line) address translation. If you don't/can't run the executable with
debug information (e.g. due to size constraints), then you can can
strip the debug information from the file that you are executing but
keep it in the executable used for off-line analysis, and the address
translation will still work correct.

I hope that made sense...

Regards,

- Mark L



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  8:56     ` Dmitry A. Kazakov
  2011-03-01  9:34       ` iloAda
@ 2011-03-01 15:23       ` Shark8
  2011-03-01 15:44         ` Dmitry A. Kazakov
  2011-03-02  0:02       ` Randy Brukardt
  2 siblings, 1 reply; 26+ messages in thread
From: Shark8 @ 2011-03-01 15:23 UTC (permalink / raw)


On Mar 1, 1:56 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
>
> Also consider this:
>
>    declare
>       Foo : exception:
>    begin
>       ...
>       raise Foo;
>    end;  -- Foo propagates out its scope!!
>

What's wrong with handling it with OTHERS?

> A possibility to handle this is exception promotion, e.g. Foo to
> Program_Error, when Foo gets finalized.

A third is to convert Exceptions to a hierarchy as stated in my last
post.
I'm not sure that's a Good Thing, but I think it's actually better
than
type extension; which I thought would be nice earlier... but the more
I
think on the problem the more it seems it would be utterly burdensome
for
implementors as well as possibly impossible-to-get-right.



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01 15:23       ` Shark8
@ 2011-03-01 15:44         ` Dmitry A. Kazakov
  0 siblings, 0 replies; 26+ messages in thread
From: Dmitry A. Kazakov @ 2011-03-01 15:44 UTC (permalink / raw)


On Tue, 1 Mar 2011 07:23:56 -0800 (PST), Shark8 wrote:

> On Mar 1, 1:56�am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>>
>> Also consider this:
>>
>> � �declare
>> � � � Foo : exception:
>> � �begin
>> � � � ...
>> � � � raise Foo;
>> � �end; �-- Foo propagates out its scope!!
>>
> 
> What's wrong with handling it with OTHERS?

You have an object of non-existent type:

   when Error : others =>

Assuming that Error is of Root_Exception_Type'Class, what should Error'Tag
return?

>> A possibility to handle this is exception promotion, e.g. Foo to
>> Program_Error, when Foo gets finalized.
> 
> A third is to convert Exceptions to a hierarchy as stated in my last
> post.

No, that does not work, because the exception type would be dead in the
handler. C++ model cannot work in Ada 2005+, because in Ada tagged types
can be local.

Further problems are overlapping choices in the exception clause. If the
semantics of

   exception
      when X =>
      when Y =>

is dispatching on the tag of the current exception, which people suggesting
class-wide exceptions have in mind. Then that would be incompatible with
the choice

      when others =>

which has the semantics of a class-wide call. If you choose that semantics
instead, then you would have to write

   exception
      when X'Class =>
      when Y'Class =>

and lose the property that alternatives do not overlap. That is way
unacceptable to me.

These are the reasons why I don't think that exception -> type mapping is
such a good idea. I prefer exception -> value mapping + contracts.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  9:34       ` iloAda
                           ` (2 preceding siblings ...)
  2011-03-01 13:27         ` Mark Lorenzen
@ 2011-03-01 16:11         ` J-P. Rosen
  2011-03-02  0:11         ` Randy Brukardt
  4 siblings, 0 replies; 26+ messages in thread
From: J-P. Rosen @ 2011-03-01 16:11 UTC (permalink / raw)


Le 01/03/2011 10:34, iloAda a �crit :
> have u guys done something like that before?
> 
Or try AdaControl, rule Exception_Propagation

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Adalog a d�m�nag� / Adalog has moved:
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  8:34     ` Dmitry A. Kazakov
@ 2011-03-02  0:00       ` Randy Brukardt
  2011-03-02  8:28         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 26+ messages in thread
From: Randy Brukardt @ 2011-03-02  0:00 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:3es12u7g6ppm.4lk5iya2a586.dlg@40tude.net...
> On Mon, 28 Feb 2011 21:54:08 -0600, Randy Brukardt wrote:
...
>> That seems like bad software management to
>> me. In any case, any such "contracts" in Ada would have to be optional 
>> (for
>> compatibility reasons), and that might actually help reduce the problems.
>
> Unless Storage_Error and Program_Error made manageable contracted
> exceptions would have only limited use.

I agree; I think that if we go this way all exceptions would have to appear 
in the contract. To make that managable, we'd also need a way to define a 
"set" of exceptions so they could be referred to together. I personally 
think that is sufficient, and it would let the compiler tell you what it 
knows about exceptions being raised.

                                         Randy.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  8:56     ` Dmitry A. Kazakov
  2011-03-01  9:34       ` iloAda
  2011-03-01 15:23       ` Shark8
@ 2011-03-02  0:02       ` Randy Brukardt
  2 siblings, 0 replies; 26+ messages in thread
From: Randy Brukardt @ 2011-03-02  0:02 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:195bsgigtzacu$.13u18z09ptrtw$.dlg@40tude.net...
...
> Also consider this:
>
>   declare
>      Foo : exception:
>   begin
>      ...
>      raise Foo;
>   end;  -- Foo propagates out its scope!!
>
> Unless Ada would have upward closures, that cannot work when Foo is a 
> type.
> I hope everybody agrees that upward closures should not be introduced.

Right; this was one of the reasons that the intended plan (in Ada 2005) to 
make exceptions extensible tagged types eventually got dropped. It just 
doesn't work very well for Ada (it could have if done initially, but it is 
too late now).

                                 Randy.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-01  9:34       ` iloAda
                           ` (3 preceding siblings ...)
  2011-03-01 16:11         ` J-P. Rosen
@ 2011-03-02  0:11         ` Randy Brukardt
  4 siblings, 0 replies; 26+ messages in thread
From: Randy Brukardt @ 2011-03-02  0:11 UTC (permalink / raw)


"iloAda" <egzgheib@gmail.com> wrote in message 
news:91988389-b17a-42cb-8f5b-9b1205604b55@y3g2000vbh.googlegroups.com...
...
>exception
> When others =>
>     --  Do something that will allow the system to keep on running
>
>have u guys done something like that before?

Sure, for the spam filter and web server, each task has a handler like this 
at the outer level to log failures; then return a failure code to the 
caller. (For the web server, this returns a 503 code to the requester; for 
the spam filter, this causes the message to be quarantined for later 
hand-analysis -- and fixing of the bug that caused the crash.) This is done 
in a block inside of a loop so that the (worker) task still continues to be 
usable for processing other requests/messages.

Both of these are "real-time" systems in that not answering a web request in 
a reasonable causes the requestor to get nothing (which is bad) or causes 
e-mail to get lost (which is bad). But the timing constraints are fairly 
loose; we have seconds (not milliseconds) to handle the problem.

For the Janus/Ada compiler and tools, we used to have such handlers, but 
they covered up errors so well that we got rid of them. It's better for the 
compiler to just crash outright because that makes customers call us with a 
report right away rather than trying to figure out what went wrong. (And 
often we can figure out the bug just from the default error walkback and a 
bit of poking in the source code -- saves lots of debugging time.)

                               Randy.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-03-02  0:00       ` Randy Brukardt
@ 2011-03-02  8:28         ` Dmitry A. Kazakov
  0 siblings, 0 replies; 26+ messages in thread
From: Dmitry A. Kazakov @ 2011-03-02  8:28 UTC (permalink / raw)


On Tue, 1 Mar 2011 18:00:32 -0600, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
> news:3es12u7g6ppm.4lk5iya2a586.dlg@40tude.net...
>> On Mon, 28 Feb 2011 21:54:08 -0600, Randy Brukardt wrote:
> ...
>>> That seems like bad software management to
>>> me. In any case, any such "contracts" in Ada would have to be optional 
>>> (for
>>> compatibility reasons), and that might actually help reduce the problems.
>>
>> Unless Storage_Error and Program_Error made manageable contracted
>> exceptions would have only limited use.
> 
> I agree; I think that if we go this way all exceptions would have to appear 
> in the contract. To make that managable, we'd also need a way to define a 
> "set" of exceptions so they could be referred to together. I personally 
> think that is sufficient, and it would let the compiler tell you what it 
> knows about exceptions being raised.

I thought about sort of conditional exceptions. E.g. storage error possibly
raised when stack has less than n storage units. The compiler should
estimate n in the cases mandated by the ARM. In other cases (recursion etc)
the program is illegal, but the programmer may specify n explicitly using a
pragma (he must know what he's doing, of course).

Another example of conditional exception would be "I don't raise, if you
don't."

And we need a mechanism of exception propagation from slave tasks to their
masters (when the task's exception contract is not null).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Forcing Exception Handling
  2011-02-28 17:27 Forcing Exception Handling iloAda
                   ` (4 preceding siblings ...)
  2011-03-01  2:08 ` Hoàng Đình Long
@ 2011-03-02 13:39 ` ytomino
  5 siblings, 0 replies; 26+ messages in thread
From: ytomino @ 2011-03-02 13:39 UTC (permalink / raw)


On Mar 1, 2:27 am, iloAda <egzgh...@gmail.com> wrote:
> Hello everybody,
>
> I was wondering if there is a way in Ada to force exception handling.
> For instance, if there is a call to a function that may raise an
> exception, force the caller to handle that exception.
> I was wondering if there is a compile time pragma that will isntruct
> the compiler to force the handling of exceptions!!
>
> Thanks guys
>
> Elie

I'm thinking exception-pass-by-argument style (?)

procedure Callee (Storage_Error : Exception_Id) is
begin
   ...
exception
   when Standard.Storage_Error => Raise_Exception (Storage_Error);
end Callee;

This function forces a caller to write the exception name explicitly.
A caller may become aware exception-handling,
and it able to classify same exception by local-exception, for
example:

Caller : declare
   Local1, Local2 : exception;
begin
   Callee (Local1'Identity); -- *1
   Callee (Local2'Identity); -- *2
exception
   when Local1 => ...; -- from *1
   when Local2 => ...; -- from *2
end Caller;



^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2011-03-02 13:39 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-28 17:27 Forcing Exception Handling iloAda
2011-02-28 17:32 ` Simon Clubley
2011-02-28 18:33   ` onox
2011-02-28 19:10     ` Simon Clubley
2011-02-28 18:34   ` Vinzent Hoefler
2011-02-28 20:20 ` Florian Weimer
2011-02-28 20:35 ` Ludovic Brenta
2011-03-01  3:54   ` Randy Brukardt
2011-03-01  8:34     ` Dmitry A. Kazakov
2011-03-02  0:00       ` Randy Brukardt
2011-03-02  8:28         ` Dmitry A. Kazakov
2011-02-28 20:38 ` Georg Bauhaus
2011-03-01  0:19   ` Shark8
2011-03-01  8:56     ` Dmitry A. Kazakov
2011-03-01  9:34       ` iloAda
2011-03-01  9:47         ` Vinzent Hoefler
2011-03-01  9:51         ` Dmitry A. Kazakov
2011-03-01 10:07           ` iloAda
2011-03-01 13:27         ` Mark Lorenzen
2011-03-01 16:11         ` J-P. Rosen
2011-03-02  0:11         ` Randy Brukardt
2011-03-01 15:23       ` Shark8
2011-03-01 15:44         ` Dmitry A. Kazakov
2011-03-02  0:02       ` Randy Brukardt
2011-03-01  2:08 ` Hoàng Đình Long
2011-03-02 13:39 ` ytomino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox