comp.lang.ada
 help / color / mirror / Atom feed
* Current Exception in a Finalise Routine
@ 2002-06-27  1:56 Chris Miller
  2002-06-27  2:38 ` David C. Hoos, Sr.
  2002-06-27 15:42 ` Stephen Leake
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Miller @ 2002-06-27  1:56 UTC (permalink / raw)


Is there any way I can find out if a Finalize routine is being called
as a result of an exception being raised and, if so, what that
exception is ?.

For example if you have

  procedure P1(...)is
     X : some_controlled_type;
  begin
     ...
  end P1;

I would like to be able to determine in the finalise procedure for X
if it is being called as a result of an exception being raised. Is
there a standard way of doing this ?. Is there a non standard way of
doing it :) ?.

The need for this could be that if a certain exception has been raised
then there may be a desire to shut down the program ASAP. In this case
there may be no need to perform all finalization since the image is
going to stopped anyway and, worse, doing so may slow down the
shutdown.

I don't know if this is going over old ground (surely this has come up
before !)but it seems we need a Ada.Exceptions.Current_Exception
function that returns either an exception_occurrence_access of the
current exception or Null_Occurrence if there is none. It would be
analogous to the current_task function.

Assume an event driven system where an exception called "Fatal_Error"
is defined and that, if it is raised, then control should be returned
to the exec ASAP. The finalize (not compiled) procedure might be

  procedure Finalize (...) is
     A : Ada.Exceptions.Exception_Occurrence_Access;
  begin
     A := Ada.Exceptions.Current_Exception (...);

     if A.all /= Ada.Exceptions.Null_Occurrence and then 

       Ada.Exceptions.Exception_Identity(A.all) = Fatal_Error'Identity
then

          -- possibly do nothing, or a minimal shutdown.

     else

       -- Do normal finalization.

     end if;

     ...
   end Finalize;

(Not sure what happens in the case of task aborts).

Has anyone got any suggestions ?. Any AI's on this ?.

Chris Miller
27 Jun 2002.



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

* Re: Current Exception in a Finalise Routine
  2002-06-27  1:56 Current Exception in a Finalise Routine Chris Miller
@ 2002-06-27  2:38 ` David C. Hoos, Sr.
  2002-06-27 15:42 ` Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: David C. Hoos, Sr. @ 2002-06-27  2:38 UTC (permalink / raw)


To begin with, Ada.Exceptions.Current_Exception is not defined in the
Ada Standard.

----- Original Message ----- 
From: "Chris Miller" <chrismiller677@hotmail.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: June 26, 2002 8:56 PM
Subject: Current Exception in a Finalise Routine


> Is there any way I can find out if a Finalize routine is being called
> as a result of an exception being raised and, if so, what that
> exception is ?.
> 
> For example if you have
> 
>   procedure P1(...)is
>      X : some_controlled_type;
>   begin
>      ...
>   end P1;
> 
> I would like to be able to determine in the finalise procedure for X
> if it is being called as a result of an exception being raised. Is
> there a standard way of doing this ?. Is there a non standard way of
> doing it :) ?.
> 
> The need for this could be that if a certain exception has been raised
> then there may be a desire to shut down the program ASAP. In this case
> there may be no need to perform all finalization since the image is
> going to stopped anyway and, worse, doing so may slow down the
> shutdown.
> 
> I don't know if this is going over old ground (surely this has come up
> before !)but it seems we need a Ada.Exceptions.Current_Exception
> function that returns either an exception_occurrence_access of the
> current exception or Null_Occurrence if there is none. It would be
> analogous to the current_task function.
> 
> Assume an event driven system where an exception called "Fatal_Error"
> is defined and that, if it is raised, then control should be returned
> to the exec ASAP. The finalize (not compiled) procedure might be
> 
>   procedure Finalize (...) is
>      A : Ada.Exceptions.Exception_Occurrence_Access;
>   begin
>      A := Ada.Exceptions.Current_Exception (...);
> 
>      if A.all /= Ada.Exceptions.Null_Occurrence and then 
> 
>        Ada.Exceptions.Exception_Identity(A.all) = Fatal_Error'Identity
> then
> 
>           -- possibly do nothing, or a minimal shutdown.
> 
>      else
> 
>        -- Do normal finalization.
> 
>      end if;
> 
>      ...
>    end Finalize;
> 
> (Not sure what happens in the case of task aborts).
> 
> Has anyone got any suggestions ?. Any AI's on this ?.
> 
> Chris Miller
> 27 Jun 2002.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 





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

* Re: Current Exception in a Finalise Routine
  2002-06-27  1:56 Current Exception in a Finalise Routine Chris Miller
  2002-06-27  2:38 ` David C. Hoos, Sr.
@ 2002-06-27 15:42 ` Stephen Leake
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Leake @ 2002-06-27 15:42 UTC (permalink / raw)


chrismiller677@hotmail.com (Chris Miller) writes:

> The need for this could be that if a certain exception has been raised
> then there may be a desire to shut down the program ASAP. In this case
> there may be no need to perform all finalization since the image is
> going to stopped anyway and, worse, doing so may slow down the
> shutdown.

To do this, use an exception handler for that "certain exception", and
call an operating system abort procedure (like C abort()), that will
bypass all finalization.

No need to do anything in a Finalize subprogram.

-- 
-- Stephe



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

end of thread, other threads:[~2002-06-27 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-27  1:56 Current Exception in a Finalise Routine Chris Miller
2002-06-27  2:38 ` David C. Hoos, Sr.
2002-06-27 15:42 ` Stephen Leake

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