comp.lang.ada
 help / color / mirror / Atom feed
* simple exception-handler
@ 1993-02-08 10:21 enterpoop.mit.edu!ira.uka.de!Germany.EU.net!urmel.informatik.rwth-aachen.
  0 siblings, 0 replies; 6+ messages in thread
From: enterpoop.mit.edu!ira.uka.de!Germany.EU.net!urmel.informatik.rwth-aachen. @ 1993-02-08 10:21 UTC (permalink / raw)


While I am trying to test my packages and subprograms,
I want to write an exception-handler, which only puts
the name of the raised exception to the standard output.
The first solution, that I found, was :

with Text_IO ;
procedure Error_IO_Test is
...
exception
  when CONSTRAINT_ERROR => Text_IO.Put_Line ("CONSTRAINT_ERROR");
  when NUMERIC_ERROR    => Text_IO.Put_Line ("NUMERIC_ERROR");
  when PROGRAM_ERROR    => Text_IO.Put_Line ("PROGRAM_ERROR");
  when STORAGE_ERROR    => Text_IO.Put_Line ("STORAGE_ERROR");
  when TASKING_ERROR    => Text_IO.Put_Line ("TASKING_ERROR");
end Error_IO_Test;

The number of lines in the exception-handler will increase,
if I take care not only for the standard exceptions, but for
the Text_IO exceptions and my own user-defined exceptions.
For this reason, I prefer a solution like this :

with Text_IO ;
procedure Error_IO_Test is
...
exception
  when others => Text_IO.Put_Line ( <Name_of_the_Error> );
end Error_IO_Test;
Of course, the above solution with Text_IO doesn't work.
Do there really exist a solution, that is easier than
writing all the names of all known exceptions ?

Please post your response.

Thanks in advance
Dirk Otte
Institut fuer Allgemeine Nachrichtentechnik
Technische Universitaet Hannover
3000 Hannover 1
Deutschland

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

* Re: simple exception-handler
@ 1993-02-08 18:27 Kenneth Anderson
  0 siblings, 0 replies; 6+ messages in thread
From: Kenneth Anderson @ 1993-02-08 18:27 UTC (permalink / raw)


In comp.lang.ada you write:

  <desire for function which prints exception name deleted>

I asked about this same topic this summer and found out that a solution
will become standard in Ada9x.  I.E. a way to do what you want will become
standard in Ada9x.  Until then, the solution is compiler-depended. It
turns out that with the Verdix compiler there is a package called
ExceptionNames (or something like that) that does the trick.  So try
looking at the documentation for your Ada compiler.  It may have the
information you need...

Good Luck,

Ken
--
-------------------------------------------------------------------------------
-
Ken Anderson                           |  "I'd much rather live in perfection,
U.C. Irvine                            |   than deal with reality." -- Kenbod
-------------------------------------------------------------------------------
-
Happy! Happy! Happy! Joy! Joy! Joy!    |  Practice random kindness and
                         -- Stimpy     |  senseless acts of beauty.
                                       |  -- Anne Herbert
-------------------------------------------------------------------------------
-

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

* Re: simple exception-handler
@ 1993-02-08 19:36 cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!h
  0 siblings, 0 replies; 6+ messages in thread
From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!h @ 1993-02-08 19:36 UTC (permalink / raw)


In article <otte.2.0@antpc.ant.uni-hannover.de> otte@antpc.ant.uni-hannover.de 
(Herr Otte) writes:

>   While I am trying to test my packages and subprograms,
>   I want to write an exception-handler, which only puts
>   the name of the raised exception to the standard output.
>   The first solution, that I found, was :
>
>   with Text_IO ;
>   procedure Error_IO_Test is
>   ...
>   exception
>     when CONSTRAINT_ERROR => Text_IO.Put_Line ("CONSTRAINT_ERROR");
>     when NUMERIC_ERROR    => Text_IO.Put_Line ("NUMERIC_ERROR");
>     when PROGRAM_ERROR    => Text_IO.Put_Line ("PROGRAM_ERROR");
>     when STORAGE_ERROR    => Text_IO.Put_Line ("STORAGE_ERROR");
>     when TASKING_ERROR    => Text_IO.Put_Line ("TASKING_ERROR");
>   end Error_IO_Test;
>
>   The number of lines in the exception-handler will increase,
>   if I take care not only for the standard exceptions, but for
>   the Text_IO exceptions and my own user-defined exceptions.
>   For this reason, I prefer a solution like this :
>
>   with Text_IO ;
>   procedure Error_IO_Test is
>   ...
>   exception
>     when others => Text_IO.Put_Line ( <Name_of_the_Error> );
>   end Error_IO_Test;
>   Of course, the above solution with Text_IO doesn't work.
>   Do there really exist a solution, that is easier than
>   writing all the names of all known exceptions ?

There's no "Current Exception Name" function in Ada, but there's
nothing barring Ada compiler vendors from including such a function in
SYSTEM or in another vendor-supplied package.  Our compiler does
provide a function like that.  You should check the Ada documentation
that came with your compiler, or ask your vendor.

                                Adam Beneschan
                                Irvine Compiler Corporation

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

* Re: simple exception-handler
@ 1993-02-08 22:40 Mark A Biggar
  0 siblings, 0 replies; 6+ messages in thread
From: Mark A Biggar @ 1993-02-08 22:40 UTC (permalink / raw)


In article <otte.2.0@antpc.ant.uni-hannover.de> otte@antpc.ant.uni-hannover.de 
(Herr Otte) writes:
>While I am trying to test my packages and subprograms,
>I want to write an exception-handler, which only puts
>the name of the raised exception to the standard output.
>The first solution, that I found, was :
>with Text_IO ;
>procedure Error_IO_Test is
>...
>exception
>  when CONSTRAINT_ERROR => Text_IO.Put_Line ("CONSTRAINT_ERROR");
>  when NUMERIC_ERROR    => Text_IO.Put_Line ("NUMERIC_ERROR");
>  when PROGRAM_ERROR    => Text_IO.Put_Line ("PROGRAM_ERROR");
>  when STORAGE_ERROR    => Text_IO.Put_Line ("STORAGE_ERROR");
>  when TASKING_ERROR    => Text_IO.Put_Line ("TASKING_ERROR");
>end Error_IO_Test;
>The number of lines in the exception-handler will increase,
>if I take care not only for the standard exceptions, but for
>the Text_IO exceptions and my own user-defined exceptions.
>For this reason, I prefer a solution like this :
>with Text_IO ;
>procedure Error_IO_Test is
>...
>exception
>  when others => Text_IO.Put_Line ( <Name_of_the_Error> );
>end Error_IO_Test;
>Of course, the above solution with Text_IO doesn't work.
>Do there really exist a solution, that is easier than
>writing all the names of all known exceptions ?

No help in Ada83 but in Ada9x you will be able to say:

with Text_IO;
procedure Error_IO_Test is
...
exception
    when E: others => Text_IO.Put_Line(Exception_Name(E));
end Error_IO_Test;

There will also be a function Exception_Occurence that will return
an implementation defined value describing the context of the actual
exception.

--
Mark Biggar
mab@wdl1.wdl.loral.com

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

* Re: simple exception-handler
@ 1993-02-09  1:59 David Emery
  0 siblings, 0 replies; 6+ messages in thread
From: David Emery @ 1993-02-09  1:59 UTC (permalink / raw)


<email to otte bounced.>
The Ada Language Issues Working Group (SIGAda ALIWG) discussed this
issue a while ago and came up with the following recommendation:

	package CURRENT_EXCEPTION is

		function EXCEPTION_NAME  return STRING;

	end CURRENT_EXCEPTION;

with the basic semantics that the name returned is the simple
identifier of the exception that would be raised by a "raise;" clause
within the context of an exception handler.  Many compiler support
this recommendation, making it reasonably portable.  

				dave

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

* Re: simple exception-handler
@ 1993-02-09 10:41 Alain Marpinard
  0 siblings, 0 replies; 6+ messages in thread
From: Alain Marpinard @ 1993-02-09 10:41 UTC (permalink / raw)


In article 0@antpc.ant.uni-hannover.de, otte@antpc.ant.uni-hannover.de (Herr Ot
te) writes:
>While I am trying to test my packages and subprograms,
>I want to write an exception-handler, which only puts
>the name of the raised exception to the standard output.
>The first solution, that I found, was :
>
>with Text_IO ;
>procedure Error_IO_Test is
>....
>exception
>  when CONSTRAINT_ERROR => Text_IO.Put_Line ("CONSTRAINT_ERROR");
>  when NUMERIC_ERROR    => Text_IO.Put_Line ("NUMERIC_ERROR");
>  when PROGRAM_ERROR    => Text_IO.Put_Line ("PROGRAM_ERROR");
>  when STORAGE_ERROR    => Text_IO.Put_Line ("STORAGE_ERROR");
>  when TASKING_ERROR    => Text_IO.Put_Line ("TASKING_ERROR");
>end Error_IO_Test;
>
>The number of lines in the exception-handler will increase,
>if I take care not only for the standard exceptions, but for
>the Text_IO exceptions and my own user-defined exceptions.
>For this reason, I prefer a solution like this :
>
>with Text_IO ;
>procedure Error_IO_Test is
>....
>exception
>  when others => Text_IO.Put_Line ( <Name_of_the_Error> );
>end Error_IO_Test;

In Ada 9X Mapping (Version 4.0, Intermetrics, December 91),
you find this definition of exception handlers :

   exception_handler_part ::=
        exception exception_handler {exception_handler}

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

    choice_parameter ::= identifier

and two supplementary functions are provided in SYSTEM:

   function EXCEPTION_NAME (X: EXCEPTION_OCCURRENCE)
        return STRING;
   function EXCEPTION_INFORMATION(X: EXCEPTION_OCCURRENCE)
        return STRING;

So you will be able to write something like this:

exception
   when ANY_EXCEPTION : others =>
         Text_IO.Put_Line( EXCEPTION_NAME(ANY_EXCEPTION));
end Error_IO_Test;

-- or something like this :
--     Text_IO.Put_Line(OUTPUT_FILE, EXCEPTION_NAME(ANY_EXCEPTION)
--          & "  " &  EXCEPTION_INFORMATION(ANY_EXCEPTION));
--      raise;

>Dirk Otte
>Institut fuer Allgemeine Nachrichtentechnik
>Technische Universitaet Hannover
>3000 Hannover 1
>Deutschland


---------------------------------------------------------------------------
Alain MARPINARD                               marpinar@insage.insa-tlse.fr
                                                    Fax : (33) 61 55 98 08

G.E.R.I.I.   (Groupe d'Etude et de Recherche en Informatique Industrielle)
D.G.E.                                      (Departement Genie Electrique)
I.N.S.A.                       (Institut National des Sciences Appliquees)
---------------------------------------------------------------------------

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

end of thread, other threads:[~1993-02-09 10:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-02-08 22:40 simple exception-handler Mark A Biggar
  -- strict thread matches above, loose matches on Subject: below --
1993-02-09 10:41 Alain Marpinard
1993-02-09  1:59 David Emery
1993-02-08 19:36 cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!h
1993-02-08 18:27 Kenneth Anderson
1993-02-08 10:21 enterpoop.mit.edu!ira.uka.de!Germany.EU.net!urmel.informatik.rwth-aachen.

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