comp.lang.ada
 help / color / mirror / Atom feed
* New tools and old exceptions
@ 1997-05-19  0:00 Robert C. Leif, Ph.D.
  1997-05-20  0:00 ` Samuel A. Mize
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Robert C. Leif, Ph.D. @ 1997-05-19  0:00 UTC (permalink / raw)



From: Bob Leif, Ph.D.
To: Comp.Lang.Ada

Many of us need all of the help that we can get. Ada.Exceptions has a
function Exception_Information(X: Exception_Occurrence) return string;
Exception_Occurrence is limited private and no simple information is given
on how to call Exception_Occurrence as an argument based on a name such as
Constraint_Error.
From the error messages that I have been generating, Constraint_Error is an
exception not an Occurrence.
Therefore how does one
Exception
When Constraint_Error =>
obtain the  Exception_Information on the Constraint_Error?
I am posting this to Comp.Lang.Ada; since, I do not believe that this is a
GNAT problem.

I would also like to note for the text book authors, that describing in
detail how to maximize the information available in the Ada exception
handler would be appreciated by the students and other readers.

Thank you.
Bob Leif




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

* Re: New tools and old exceptions
  1997-05-19  0:00 New tools and old exceptions Robert C. Leif, Ph.D.
@ 1997-05-20  0:00 ` Samuel A. Mize
  1997-05-20  0:00 ` Stephen Leake
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Samuel A. Mize @ 1997-05-20  0:00 UTC (permalink / raw)



Robert C. Leif, Ph.D. wrote:
> 
> From: Bob Leif, Ph.D.
> To: Comp.Lang.Ada
> 
> ... Ada.Exceptions has a
> function Exception_Information(X: Exception_Occurrence) return string;
> Exception_Occurrence is limited private and no simple information is given
> on how to call Exception_Occurrence as an argument based on a name such as
> Constraint_Error.
> From the error messages that I have been generating, Constraint_Error is an
> exception not an Occurrence.
> Therefore how does one
> Exception
> When Constraint_Error =>
> obtain the  Exception_Information on the Constraint_Error?

Check the example in RM 11.4.2.

Quick info:

- To get ahold of the current Exception_Occurrence in a handler, put a
  parameter in the "when" clause:

    begin
      null;
    when E: others =>
      -- E is implicitly of type Exception_Occurrence
      Text_Io.Put_Line
        ("DIE DIE DIE " & Ada.Exceptions.Exception_Information (E);
    end;

- To just raise a given exception, use a "raise" statement:

    raise Constraint_Error;

- But to raise it and attach your own text (which can then be retrieved
  by Exception_Information) use Exceptions.Raise_Exception, using the
  'Identity attribute to get the exception's ID:

    Ada.Exceptions.Raise_Exception
      (Constraint_Error'Identity,
       "Failed in region 7 due to stupid user error");

Samuel Mize

> I am posting this to Comp.Lang.Ada; since, I do not believe that this is a
> GNAT problem.
> 
> I would also like to note for the text book authors, that describing in
> detail how to maximize the information available in the Ada exception
> handler would be appreciated by the students and other readers.
> 
> Thank you.
> Bob Leif

-- Samuel Mize           (817) 619-8622               "Team Ada"
-- Hughes Training Inc.  PO Box 6171 m/s 400, Arlington TX 76005




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

* Re: New tools and old exceptions
  1997-05-19  0:00 New tools and old exceptions Robert C. Leif, Ph.D.
  1997-05-20  0:00 ` Samuel A. Mize
  1997-05-20  0:00 ` Stephen Leake
@ 1997-05-20  0:00 ` Jeff Carter
  1997-05-21  0:00 ` David C. Hoos, Sr.
  3 siblings, 0 replies; 5+ messages in thread
From: Jeff Carter @ 1997-05-20  0:00 UTC (permalink / raw)



Robert C. Leif, Ph.D. wrote:
> 
> From: Bob Leif, Ph.D.
> To: Comp.Lang.Ada
> 
> Many of us need all of the help that we can get. Ada.Exceptions has a
> function Exception_Information(X: Exception_Occurrence) return string;
> Exception_Occurrence is limited private and no simple information is given
> on how to call Exception_Occurrence as an argument based on a name such as
> Constraint_Error.
> From the error messages that I have been generating, Constraint_Error is an
> exception not an Occurrence.
> Therefore how does one
> Exception
> When Constraint_Error =>
> obtain the  Exception_Information on the Constraint_Error?
> I am posting this to Comp.Lang.Ada; since, I do not believe that this is a
> GNAT problem.
> 
> I would also like to note for the text book authors, that describing in
> detail how to maximize the information available in the Ada exception
> handler would be appreciated by the students and other readers.
> 
> Thank you.
> Bob Leif

Check out ARM 11.2, which defines an exception handler:

exception_handler ::=
         when [choice_parameter_specification:] exception_choice {|
exception_choice} =>
            sequence_of_statements

So you'd want something like

exception -- Block_Name
when C_E : Constraint_Error =>
   -- Something using Exception_Information (C_E):
   Text_Io.Put_Line (Item => Ada.Exceptions.Exception_Information (C_E)
);
... -- Other handlers
end Block_Name;
-- 
Jeff Carter  PGP:1024/440FBE21
Auntie-spam reply to; try ( carter @ innocon . com )
"Now go away, or I shall taunt you a second time."
Monty Python & the Holy Grail




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

* Re: New tools and old exceptions
  1997-05-19  0:00 New tools and old exceptions Robert C. Leif, Ph.D.
  1997-05-20  0:00 ` Samuel A. Mize
@ 1997-05-20  0:00 ` Stephen Leake
  1997-05-20  0:00 ` Jeff Carter
  1997-05-21  0:00 ` David C. Hoos, Sr.
  3 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 1997-05-20  0:00 UTC (permalink / raw)



Robert C. Leif, Ph.D. wrote:
> ... 
> Therefore how does one

> Exception
> When Constraint_Error =>
> obtain the  Exception_Information on the Constraint_Error?

> I am posting this to Comp.Lang.Ada; since, I do not believe that this is a
> GNAT problem.

exception
when E : Constraint_Error =>
	Put_Line (Exception_Information (E));


E is an object of type Exception_Occurence.

> Thank you.
> Bob Leif

-- 
- Stephe




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

* Re: New tools and old exceptions
  1997-05-19  0:00 New tools and old exceptions Robert C. Leif, Ph.D.
                   ` (2 preceding siblings ...)
  1997-05-20  0:00 ` Jeff Carter
@ 1997-05-21  0:00 ` David C. Hoos, Sr.
  3 siblings, 0 replies; 5+ messages in thread
From: David C. Hoos, Sr. @ 1997-05-21  0:00 UTC (permalink / raw)



Here's an excerpt from an internal e-mail to one of my colleagues just last
week which, I believe, gives the information pertinent to your query.

---- begin excerpt -----
In general however, you can make such exception messages more informative
in Ada95 by doing the following:

    1.  with Ada.Exceptions;

    2.  Make your exception handlers look something like the following:

        exception
            when E: others=>
                  Ada.Text_IO.Put_Line
                     ("Exception caught in main procedure");
                  Ada.Text_IO.Put_Line
                     ("Exception information:")
                  Ada.Text_IO.Put_Line
                     (Ada.Exceptions.Exception_Information (E));
        end;

     The "E" in this case (any identifier will do) identifies the exception
occurrence, and is declared "on the fly" by placing it immediately
following the "when" in an exception handler, followed by the colon.
Then this identifier can be passed to any of the subprograms declared in
Ada.Exceptions with parameters of type Exception_ID.

     The exception information can include a message provided at the point
the exception was raised.

     The way this is done is -- instead of a statement like 
"raise My_Exception;" you would say
     Ada.Exceptions.Raise_Exception
          (E => My_Exception'Identity,
           Message "raised in My_Package.My_Subprogram because ......");

    This enhanced exception capability in Ada95 makes it possible to place
all of the relevant information about an exception in the message
(including relevant data values, etc.) at the point it is raised.
Then if it's an exception which should never occur, the exception never
need be handled explicitly, but it can be implicitly handled in a
"when others" handler in the main program, and still have all of the
relevant information about where and why it was raised.
------ end excerpt ------

I hope this helps.

David C. Hoos, Sr.
http://www.ada95.com
http://www.dbhwww.com

Robert C. Leif, Ph.D. <rleif@RLEIF.COM> wrote in article
<3.0.32.19970519223408.0070cc14@mail.4dcomm.com>...
> From: Bob Leif, Ph.D.
> To: Comp.Lang.Ada
> 
> Many of us need all of the help that we can get. Ada.Exceptions has a
> function Exception_Information(X: Exception_Occurrence) return string;
> Exception_Occurrence is limited private and no simple information is
given
> on how to call Exception_Occurrence as an argument based on a name such
as
> Constraint_Error.
> From the error messages that I have been generating, Constraint_Error is
an
> exception not an Occurrence.
> Therefore how does one
> Exception
> When Constraint_Error =>
> obtain the  Exception_Information on the Constraint_Error?
> I am posting this to Comp.Lang.Ada; since, I do not believe that this is
a
> GNAT problem.
> 
> I would also like to note for the text book authors, that describing in
> detail how to maximize the information available in the Ada exception
> handler would be appreciated by the students and other readers.
> 
> Thank you.
> Bob Leif
> 




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

end of thread, other threads:[~1997-05-21  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-19  0:00 New tools and old exceptions Robert C. Leif, Ph.D.
1997-05-20  0:00 ` Samuel A. Mize
1997-05-20  0:00 ` Stephen Leake
1997-05-20  0:00 ` Jeff Carter
1997-05-21  0:00 ` David C. Hoos, Sr.

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