comp.lang.ada
 help / color / mirror / Atom feed
* newbie can't get exceptions to work!
@ 2001-04-05  3:19 Jeff Shipman
  2001-04-05  4:25 ` Ed Falis
                   ` (2 more replies)
  0 siblings, 3 replies; 88+ messages in thread
From: Jeff Shipman @ 2001-04-05  3:19 UTC (permalink / raw)


Ok, I'm creating a generic stack package and I think
I've done everything properly, but I cannot seem to
get my STACK_EXCEPTION to work. This is what it
looks like in my gen_stack.ads file:

generic
   LEN : NATURAL := 100;      -- Size of the stack (default 100
   type ELM is private;       -- Used to store element type

   package GEN_STACK is
      STACK_ERROR : exception;        -- Raised when something bad
happens.
      
      procedure PUSH(E : in ELM);     -- Push E into the stack
      procedure POP(E : out ELM);     -- Pop element from stack; store
in E
      
      function  FULL return BOOLEAN;  -- Returns TRUE if stack is full
      function  EMPTY return BOOLEAN; -- Returns TRUE if stack is empty
   end GEN_STACK;

and I can use it just fine in my gen_stack.adb. The use_gen_stack.adb
file which uses the stacks works great up until the point I want to
handle the exceptions. My code for handling it looks like this:

   -- Handle exceptions
   exception
      when STACK_ERROR =>
      begin
         put_line("Error: Stack underflow/overflow");
      end;

When I try to compile, I get the following errors:

use_gen_stack.adb:214:12: "STACK_ERROR" is not visible
use_gen_stack.adb:214:12: multiple use clauses cause hiding
use_gen_stack.adb:214:12: hidden declaration at gen_stack.ads:14,
instance at line 32
use_gen_stack.adb:214:12: hidden declaration at gen_stack.ads:14,
instance at line 31
use_gen_stack.adb:214:12: hidden declaration at gen_stack.ads:14,
instance at line 30
use_gen_stack.adb:214:12: hidden declaration at gen_stack.ads:14,
instance at line 29
use_gen_stack.adb:214:12: hidden declaration at gen_stack.ads:14,
instance at line 28
use_gen_stack.adb:214:12: hidden declaration at gen_stack.ads:14,
instance at line 27
gnatmake: "use_gen_stack.adb" compilation error
make: *** [use_gen_stack] Error 4

Those relevant lines of code are:

   -- Convenient stack types we'll need
   package INT_STACK is new GEN_STACK(ELM => INTEGER, LEN => 10);
   package INT2_STACK is new GEN_STACK(ELM => INTEGER, LEN => 5);
   package FLOAT_STACK is new GEN_STACK(ELM => FLOAT, LEN => 12);
   package CHAR_STACK is new GEN_STACK(ELM => CHARACTER, LEN => 14);
   package STR_STACK is new GEN_STACK(ELM => STR, LEN => 3);
   package DAY_STACK is new GEN_STACK(ELM => DAY, LEN => 7);

   use INT_STACK; use INT2_STACK; use FLOAT_STACK;
   use CHAR_STACK; use STR_STACK; use DAY_STACK;

At the top of my file, I have the following:

with text_io; use text_io;
with ada.float_text_io; use ada.float_text_io;
with gen_stack;

I've tried putting in use STACK_ERROR in multiple
places. I just can't get this exception handler
to compile. I would greatly appreciate it if someone
could help me. I'm sure it's a very simple thing
I'm forgetting. By the error message, it seems like
it doesn't like the multiple instances of use, but
If I want to use those packages I created, I have
to do that!

Thanks in advance,
 
Jeff "Shippy" Shipman     E-Mail: shippy@nmt.edu
Computer Science Major    ICQ: 1786493
New Mexico Institute of Mining and Technology
Homepage: http://www.nmt.edu/~shippy



^ permalink raw reply	[flat|nested] 88+ messages in thread
* Re: newbie can't get exceptions to work!
@ 2001-04-05  5:26 Christoph Grein
  0 siblings, 0 replies; 88+ messages in thread
From: Christoph Grein @ 2001-04-05  5:26 UTC (permalink / raw)
  To: comp.lang.ada

   package INT_STACK  is new GEN_STACK(ELM => INTEGER, LEN => 10);
   package INT2_STACK is new GEN_STACK(ELM => INTEGER, LEN =>  5);

With these two instantiations, you get two exceptions STACK_ERROR:
  INT_STACK.STACK_ERROR and INT2_STACK.STACK_ERROR.

So write:

  ...
exception
  when INT_STACK.STACK_ERROR | INT2_STACK.STACK_ERROR =>
    Handle_them;  -- note that you do not need a begin end block here.
end;





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

end of thread, other threads:[~2001-04-17  9:08 UTC | newest]

Thread overview: 88+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-05  3:19 newbie can't get exceptions to work! Jeff Shipman
2001-04-05  4:25 ` Ed Falis
2001-04-05 11:00   ` martin.m.dowie
2001-04-05 14:21     ` Ted Dennison
2001-04-05 17:50       ` Fraser Wilson
2001-04-05  4:34 ` Jeff Shipman
2001-04-05  4:59 ` Wilhelm Spickermann
2001-04-05 14:14   ` Ted Dennison
2001-04-05 16:37     ` Wilhelm Spickermann
2001-04-06 13:09     ` Marc A. Criley
2001-04-06 15:04       ` Ted Dennison
2001-04-06 16:43       ` Robert A Duff
2001-04-06 17:39         ` Ted Dennison
2001-04-06 21:50           ` Robert A Duff
2001-04-06 20:11         ` Brian Rogoff
2001-04-06 22:20           ` Robert A Duff
2001-04-06 23:04             ` Brian Rogoff
2001-04-07  5:48               ` Jeffrey Carter
2001-04-10  1:29                 ` Robert A Duff
2001-04-07 19:30               ` Robert A Duff
2001-04-07 21:17                 ` Brian Rogoff
2001-04-07 21:25                   ` Ayende Rahien
2001-04-07 22:57                     ` David Starner
2001-04-08 12:10                       ` Ayende Rahien
2001-04-08  2:12                     ` Larry Hazel
2001-04-08 12:12                       ` Ayende Rahien
2001-04-09 16:20                         ` Larry Hazel
2001-04-10  2:38                           ` Ayende Rahien
2001-04-10  3:25                             ` James Rogers
2001-04-08 22:18                       ` Brian Rogoff
2001-04-09 15:14                         ` Ted Dennison
2001-04-09 17:23                           ` Brian Rogoff
2001-04-09 18:23                             ` Laurent Guerby
2001-04-09 19:15                               ` Brian Rogoff
2001-04-10 18:21                                 ` Laurent Guerby
2001-04-10 19:44                                   ` Brian Rogoff
2001-04-11 18:03                                     ` Laurent Guerby
2001-04-11 18:33                                       ` Samuel T. Harris
2001-04-14  0:06                                         ` Robert A Duff
2001-04-12  1:42                                       ` Mike Silva
2001-04-12  2:38                                       ` Brian Rogoff
2001-04-12 23:23                                         ` Laurent Guerby
2001-04-13  2:44                                           ` Brian Rogoff
2001-04-11 13:24                                   ` Ayende Rahien
2001-04-11 13:14                                     ` Mats Karlssohn
2001-04-11 15:08                                       ` Ayende Rahien
2001-04-11 21:42                                       ` Fraser Wilson
2001-04-12 23:55                                         ` Robert A Duff
2001-04-10  2:12                               ` Robert A Duff
2001-04-10  3:47                                 ` Brian Rogoff
2001-04-10 13:40                                 ` Ada keywords (was: Re: newbie can't get exceptions to work!) Marin David Condic
2001-04-10 14:26                                   ` Jean-Pierre Rosen
2001-04-09 20:49                             ` newbie can't get exceptions to work! Ted Dennison
2001-04-09 21:44                               ` Brian Rogoff
2001-04-09 21:59                                 ` Ted Dennison
2001-04-10  2:54                                   ` Ayende Rahien
2001-04-10 14:00                                     ` Ted Dennison
2001-04-10 17:44                                     ` Fraser Wilson
2001-04-10  6:59                               ` Mats Karlssohn
2001-04-10 14:18                                 ` Ted Dennison
2001-04-10 16:27                                   ` Mark Biggar
2001-04-11 11:55                                     ` Mats Karlssohn
2001-04-11 14:34                                       ` Samuel T. Harris
2001-04-11 15:50                                         ` Pat Rogers
2001-04-12  6:27                                         ` Mats Karlssohn
2001-04-11 11:49                                   ` Mats Karlssohn
2001-04-11 15:38                                     ` Robert A Duff
2001-04-13 16:12                             ` Matthew Woodcraft
2001-04-10  1:41                   ` Robert A Duff
2001-04-10  3:03                     ` James Rogers
2001-04-10  3:58                       ` Brian Rogoff
2001-04-10 21:48                         ` Ted Dennison
2001-04-11 15:09                           ` Ayende Rahien
2001-04-11 21:57                             ` James Rogers
2001-04-11 23:13                               ` Brian Rogoff
2001-04-12  6:33                                 ` Mats Karlssohn
2001-04-12 16:38                                   ` Brian Rogoff
2001-04-17  7:04                                     ` Mats Karlssohn
2001-04-17  9:08                                       ` Jean-Pierre Rosen
2001-04-12 15:16                               ` Ted Dennison
2001-04-12 21:22                                 ` James Rogers
2001-04-10  4:26                     ` Brian Rogoff
2001-04-11 15:30                       ` Robert A Duff
2001-04-11 17:33                         ` Brian Rogoff
2001-04-10  1:26               ` Robert A Duff
2001-04-10  2:11                 ` Brian Rogoff
2001-04-14  0:00                   ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
2001-04-05  5:26 Christoph Grein

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