* Re: Love's exception handling
@ 1996-09-13 0:00 Chris Sparks
1996-09-16 0:00 ` Robert B. Love
0 siblings, 1 reply; 4+ messages in thread
From: Chris Sparks @ 1996-09-13 0:00 UTC (permalink / raw)
I was experimenting with Mr. Love's exception handling example.
This was my first working version. I then proceeded to clean up this example
and came up with code following after this.
-------------------------------------------------------------------------------
> with Ada.Exceptions; use Ada.Exceptions;
> with Text_io; use Text_io;
>
> procedure Exception_demo is
>
> type A_String is access String;
>
> Error_list: array (1..3) of A_String;
>
> procedure Square is begin
>
> raise Constraint_error;
>
> exception
> when Error_in_square_function: others =>
>
> declare
>
> Eo : Exception_Occurrence;
> Ei : Exception_Id;
>
> begin
> Ada.Exceptions.Save_occurrence (Eo, Error_in_square_function);
>
> Ei := Exception_identity (Eo);
> Error_List(1) := new String'(Exception_name (Ei) & " was hit Square");
>
> Raise_exception (Ei, Error_List(1).all);
>
> end;
>
> end Square;
>
> procedure Compute is begin
>
> Square;
>
> exception
> when Error_in_compute: others =>
>
> declare
>
> Eo : Exception_Occurrence;
> Ei : Exception_Id;
>
> begin
> Ada.Exceptions.Save_occurrence (Eo, Error_in_compute);
>
> Ei := Exception_identity (Eo);
> Error_List(2) := new String'(Exception_name (Ei) & " was hit
Compute");
>
> Raise_exception (Ei, Error_List(2).all);
>
> end;
>
> end Compute;
>
> begin
>
> Compute;
>
> exception
> when Error_in_demo: others =>
>
> declare
>
> Eo : Exception_Occurrence;
> Ei : Exception_Id;
>
> begin
> Ada.Exceptions.Save_occurrence (Eo, Error_in_demo);
>
> Ei := Exception_identity (Eo);
> Error_List(3) := new String'(Exception_name (Ei) & " was hit
Exception_Demo");
>
> end;
>
> for I in Error_list'range loop
> -- Text_io.Put_line ("Message : " & Exception_message
(Error_list(I).EO));
> -- Text_io.Put_line ("Name : " & Exception_name
(Error_list(I).EO));
> -- Text_io.Put_line ("Informaton : " & Exception_information
(Error_list(I).EO));
> Text_io.Put_line ("Info : " & Error_list(I).all);
> end loop;
>
> end Exception_demo;
-------------------------------------------------------------------------------
I thought the following might be useful to others. That is why I am posting
this to cla. It probably can be cleaned up to use internal data structures
instead of a constrained array (like linked lists).
What would be nice, in accordance with a previous post I sent out, to be able
to ascertain the program name without explicitly using a string literal. :-)
This a freebee, so enjoy. BTW no one should try to copyright this okay :-0
Chris B. Sparks (aka Mr. Ada)
sparks@aisf.com
-------------------------------------------------------------------------------
> with Ada.Exceptions; use Ada.Exceptions;
>
> package Ex is
>
> type A_String is access String;
>
> Error_list: array (1..3) of A_String;
>
> procedure Handler
> (Target : in Exception_Occurrence_Access;
> Index : in Integer;
> P_Name : in String;
> Elevate : in Boolean);
>
> end Ex;
> --------------------------
> package body Ex is
>
> procedure Handler
> (Target : in Exception_Occurrence_Access;
> Index : in Integer;
> P_Name : in String;
> Elevate : in Boolean) is
>
> Ei : Exception_Id;
>
> begin
> Ei := Exception_identity (Target.all);
> Error_List (Index) := new String'(P_Name & ":" & Exception_name (Ei));
>
> case Elevate is
> when True => Raise_exception (Ei, Error_List (Index).all);
> when False => null;
> end case;
>
> end Handler;
>
> end Ex;
> --------------------------
> with Ada.Exceptions; use Ada.Exceptions;
> with Text_io; use Text_io;
> with Ex; use Ex;
>
> procedure Exception_demo is
>
> procedure Square is begin
>
> raise Constraint_error;
>
> exception
> when Error_in_square_function: others =>
> Ex.Handler (Save_Occurrence (Error_in_Square_Function), 1, "Square",
True);
>
> end Square;
>
> procedure Compute is begin
>
> Square;
>
> exception
> when Error_in_compute: others =>
> Ex.Handler (Save_Occurrence (Error_in_compute), 2, "Compute", True);
>
> end Compute;
>
> begin
>
> Compute;
>
> exception
> when Error_in_demo: others =>
> Ex.Handler (Save_Occurrence (Error_in_Demo), 3, "Exception_Demo", False);
>
> for I in Error_list'range loop
> Text_io.Put_line ("Info : " & Error_list(I).all);
> end loop;
>
> end Exception_demo;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Love's exception handling
1996-09-13 0:00 Love's exception handling Chris Sparks
@ 1996-09-16 0:00 ` Robert B. Love
1996-09-20 0:00 ` Richard Riehle
1996-09-20 0:00 ` Richard Riehle
0 siblings, 2 replies; 4+ messages in thread
From: Robert B. Love @ 1996-09-16 0:00 UTC (permalink / raw)
Cc: sparks
In <INFO-ADA%96091315275250@LISTSERV.NODAK.EDU> Chris Sparks wrote:
> I was experimenting with Mr. Love's exception handling example.
>
> This a freebee, so enjoy. BTW no one should try to copyright this
okay :-0
Uh, the original source for this is the current issue of the Journal
of Object Oriented Programming in the monthly Ada column written by
Richard Riehle. I made only 2 minor changes so all
credit/blame/copyright/
gratitude goes to him.
This had proved most instructional to me, from learing about new
exception features, to playing with competing compilers.
----------------------------------------------------------------
Bob Love, rlove@neosoft.com (local) MIME & NeXT Mail OK
rlove@raptor.rmnug.org (permanent) PGP key available
----------------------------------------------------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Love's exception handling
1996-09-16 0:00 ` Robert B. Love
@ 1996-09-20 0:00 ` Richard Riehle
1996-09-20 0:00 ` Richard Riehle
1 sibling, 0 replies; 4+ messages in thread
From: Richard Riehle @ 1996-09-20 0:00 UTC (permalink / raw)
To: Robert B. Love; +Cc: sparks
On 16 Sep 1996, Robert B. Love wrote:
> Uh, the original source for this is the current issue of the Journal
> of Object Oriented Programming in the monthly Ada column written by
> Richard Riehle. I made only 2 minor changes so all
> credit/blame/copyright/
> gratitude goes to him.
Thank you Robert. My hide is relatively durable, so I accept any
criticism directed toward my exception example. I am trying to
include provocative examples in my JOOP column, so comments on
alternatives to my examples are quite welcome. In fact, we can
arrange to include some of them in the Letters section if the
editor of JOOP agrees on their potential virtue.
> This had proved most instructional to me, from learing about new
> exception features, to playing with competing compilers.
Glad to hear this. I am finding that many people are so enamoured
of the OOP features of the new standard they overlook some of the
more powerful extensions represented by such packages as
Ada.Exceptions. That was my reason for departing from strictly
OOP theme in this article and focusing on this incredibily useful
new feature of Ada 95.
As to the copyright issue, I have no need to make any claims. The
publisher may have some interest in this, but they would lose their
subscribers pretty quickly if they started nitpicking about people
actually using the code examples to learn and do real work.
Richard Riehle
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Love's exception handling
1996-09-16 0:00 ` Robert B. Love
1996-09-20 0:00 ` Richard Riehle
@ 1996-09-20 0:00 ` Richard Riehle
1 sibling, 0 replies; 4+ messages in thread
From: Richard Riehle @ 1996-09-20 0:00 UTC (permalink / raw)
To: Robert B. Love; +Cc: sparks
Reposting article removed by rogue canceller.
On 16 Sep 1996, Robert B. Love wrote:
> Uh, the original source for this is the current issue of the Journal
> of Object Oriented Programming in the monthly Ada column written by
> Richard Riehle. I made only 2 minor changes so all
> credit/blame/copyright/
> gratitude goes to him.
Thank you Robert. My hide is relatively durable, so I accept any
criticism directed toward my exception example. I am trying to
include provocative examples in my JOOP column, so comments on
alternatives to my examples are quite welcome. In fact, we can
arrange to include some of them in the Letters section if the
editor of JOOP agrees on their potential virtue.
> This had proved most instructional to me, from learing about new
> exception features, to playing with competing compilers.
Glad to hear this. I am finding that many people are so enamoured
of the OOP features of the new standard they overlook some of the
more powerful extensions represented by such packages as
Ada.Exceptions. That was my reason for departing from strictly
OOP theme in this article and focusing on this incredibily useful
new feature of Ada 95.
As to the copyright issue, I have no need to make any claims. The
publisher may have some interest in this, but they would lose their
subscribers pretty quickly if they started nitpicking about people
actually using the code examples to learn and do real work.
Richard Riehle
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1996-09-20 0:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-13 0:00 Love's exception handling Chris Sparks
1996-09-16 0:00 ` Robert B. Love
1996-09-20 0:00 ` Richard Riehle
1996-09-20 0:00 ` Richard Riehle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox