comp.lang.ada
 help / color / mirror / Atom feed
* I am not understanding user defined exceptions
@ 2017-02-03 20:27 patrick
  2017-02-03 21:08 ` Randy Brukardt
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: patrick @ 2017-02-03 20:27 UTC (permalink / raw)


Hi Everyone

I am not understanding user defined exceptions. This little program will ask the user for integer entry twice. If I type 1 at the first entry, things work as expected and the exception is handled.

However if I type, 2 and then 1, an exception is not raised at the second text_io.get.

If we type something like :    
         if x = 1
         then
           raise Foo_Error;
         end if ;
 
will x not be tested for exceptions conditions automatically from that point onward? If so, why would it not raise an exception if the second text_io.get came back with 1 ?

Sorry for what will very likely be a stupid question-Patrick






          with ada.integer_text_io ;
          with ada.text_io ;
       --
       --
       --
       --
       --
       --
        procedure test_exceptions is

        package text_io renames ada.text_io ;
        package int_text_io renames ada.integer_text_io ;

        Foo_Error : exception ;
        x : integer ;
        begin
           
         int_text_io.get(x) ;

         if x = 1
         then
           raise Foo_Error;
         end if ;
 

         int_text_io.get(x) ;

     -- why does execution reach this point if x is 1 after user input
         if x = 1
         then
            text_io.put_line("x is 1, why wasn't an exception triggered?") ;
         end if ;
 

        text_io.put_line("ended without exceptions") ;


        exception
           when Foo_Error =>
              text_io.put("error handled") ;
        end test_exceptions;


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

end of thread, other threads:[~2017-02-15  9:32 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-03 20:27 I am not understanding user defined exceptions patrick
2017-02-03 21:08 ` Randy Brukardt
2017-02-03 22:41   ` patrick
2017-02-04  1:26 ` Dennis Lee Bieber
2017-02-04  6:58   ` J-P. Rosen
2017-02-04 17:08     ` Simon Wright
2017-02-08 17:55       ` Georg Bauhaus
2017-02-08 23:37         ` Randy Brukardt
2017-02-09 19:08           ` Robert A Duff
2017-02-09 21:47             ` Randy Brukardt
2017-02-09 22:52               ` Robert A Duff
2017-02-10  9:52                 ` Simon Wright
2017-02-10 10:11                   ` Dmitry A. Kazakov
2017-02-10 20:56                 ` Randy Brukardt
2017-02-10 21:09                 ` Randy Brukardt
2017-02-10 22:07                   ` Dmitry A. Kazakov
2017-02-13 23:20                     ` Randy Brukardt
2017-02-14  8:39                       ` Dmitry A. Kazakov
2017-02-14 20:07                         ` Randy Brukardt
2017-02-15  9:32                           ` Dmitry A. Kazakov
2017-02-10 23:53                   ` Shark8
2017-02-09  0:36         ` Robert A Duff
2017-02-09  7:43           ` Simon Wright
2017-02-09 19:15             ` Robert A Duff
2017-02-09 20:39               ` Randy Brukardt
2017-02-09 21:06               ` Randy Brukardt
2017-02-09 23:08                 ` Robert A Duff
2017-02-04  8:41 ` Simon Wright

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