comp.lang.ada
 help / color / mirror / Atom feed
* Error checking for type incompatibility
@ 2001-12-11  0:28 Ben
  2001-12-11  0:49 ` Mark Lundquist
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ben @ 2001-12-11  0:28 UTC (permalink / raw)


Hi, 
I am new to Ada. I decided I would try to learn a new language and Ada
seemed like a fun project. I got a few books, and one of them has
challenge problem where I am supposed to do some error checking on
input. This includes checking to make sure that the input type is
correct. More specifically: the program is supposed to accept only
integer values. So I need to be able to have an error handler that
will recognize if someone tries to enter a noninteger value and ask
them to re-enter a correct value. Since this is a "challenge problem"
they are not giving me alot to work on here. I checked another book,
and it had some examples on error handling, but not at the level I
need. And neither book had any example code that was helpful.
Remember, I'm new to Ada (from the C++ world) so packages are new to
me. What do I need folks. Your help is greatly appreciated.

Thanks,
Ben



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

* Re: Error checking for type incompatibility
  2001-12-11  0:28 Error checking for type incompatibility Ben
@ 2001-12-11  0:49 ` Mark Lundquist
  2001-12-11  7:35 ` Preben Randhol
  2001-12-11 16:31 ` Jerry Petrey
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Lundquist @ 2001-12-11  0:49 UTC (permalink / raw)



"Ben" <cptnben@gisco.net> wrote in message
news:bf8dbe70.0112101628.1092b75a@posting.google.com...
> Hi,
> I am new to Ada. I decided I would try to learn a new language and Ada
> seemed like a fun project.

cool :-)

> I got a few books, and one of them has
> challenge problem where I am supposed to do some error checking on
> input. This includes checking to make sure that the input type is
> correct. More specifically: the program is supposed to accept only
> integer values. So I need to be able to have an error handler that
> will recognize if someone tries to enter a noninteger value and ask
> them to re-enter a correct value. Since this is a "challenge problem"
> they are not giving me alot to work on here. I checked another book,
> and it had some examples on error handling, but not at the level I
> need. And neither book had any example code that was helpful.
> Remember, I'm new to Ada (from the C++ world) so packages are new to
> me. What do I need folks. Your help is greatly appreciated.
>
> Thanks,
> Ben

Let me ask you this: how would you do this in C++?  ( I don't mean that
rhetorically; I can imagine different approaches to this, and I'm wondering
which one seems right to you).  What is your unit of input, e.g. do they
enter a complete expression on a line, or just one token, or what?  How are
you doing your tokenization?

-- mark






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

* Re: Error checking for type incompatibility
  2001-12-11  0:28 Error checking for type incompatibility Ben
  2001-12-11  0:49 ` Mark Lundquist
@ 2001-12-11  7:35 ` Preben Randhol
  2001-12-11 16:31 ` Jerry Petrey
  2 siblings, 0 replies; 4+ messages in thread
From: Preben Randhol @ 2001-12-11  7:35 UTC (permalink / raw)


On 10 Dec 2001 16:28:15 -0800, Ben wrote:
> Hi, 
> I am new to Ada. I decided I would try to learn a new language and Ada
> seemed like a fun project. I got a few books, and one of them has
> challenge problem where I am supposed to do some error checking on
> input. This includes checking to make sure that the input type is
> correct. More specifically: the program is supposed to accept only
> integer values. So I need to be able to have an error handler that
> will recognize if someone tries to enter a noninteger value and ask
> them to re-enter a correct value. Since this is a "challenge problem"
> they are not giving me alot to work on here. I checked another book,
> and it had some examples on error handling, but not at the level I
> need. And neither book had any example code that was helpful.

One way is to use:

   http://www.it.bton.ac.uk/staff/je/adacraft/ch07.htm

> Remember, I'm new to Ada (from the C++ world) so packages are new to
> me. What do I need folks. Your help is greatly appreciated.

Perhaps you should read more before you try this problem. Which book is
it by the way?

Preben
-- 
 ()   Join the worldwide campaign to protect fundamental human rights.
'||}
{||'                                           http://www.amnesty.org/



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

* Re: Error checking for type incompatibility
  2001-12-11  0:28 Error checking for type incompatibility Ben
  2001-12-11  0:49 ` Mark Lundquist
  2001-12-11  7:35 ` Preben Randhol
@ 2001-12-11 16:31 ` Jerry Petrey
  2 siblings, 0 replies; 4+ messages in thread
From: Jerry Petrey @ 2001-12-11 16:31 UTC (permalink / raw)




Ben wrote:
> 
> Hi,
> I am new to Ada. I decided I would try to learn a new language and Ada
> seemed like a fun project. I got a few books, and one of them has
> challenge problem where I am supposed to do some error checking on
> input. This includes checking to make sure that the input type is
> correct. More specifically: the program is supposed to accept only
> integer values. So I need to be able to have an error handler that
> will recognize if someone tries to enter a noninteger value and ask
> them to re-enter a correct value. Since this is a "challenge problem"
> they are not giving me alot to work on here. I checked another book,
> and it had some examples on error handling, but not at the level I
> need. And neither book had any example code that was helpful.
> Remember, I'm new to Ada (from the C++ world) so packages are new to
> me. What do I need folks. Your help is greatly appreciated.
> 
> Thanks,
> Ben


Ben, here is a simple example of error handling from a program
I wrote years ago.  Of course you won't have some of the
subprograms that it uses but hopefully it will show you 
the basic concept and structure for input error handling.
It expects the user to enter 4 hex digits and prints out
the decimal value and what that represents in voltage in
this particular application.  The procedure HEX_GET returns 
an ERROR flag if the numbers entered are not valid hex digits,
in which case the exception ENTRY_ERROR is raised and the 
exception handler (inside the loop) prints out the retry 
message and control returns to the end of the block 
(still inside the loop) so the HEX_GET is called again. 
Hope this helps.

Jerry

procedure Input_Hex_Number is
   loop
      ERASE_SCREEN;
      --
      CURSOR_TO(3, 1);
      PUT(" Enter four digit Hex number: ");
      loop
         begin
	    HEX_GET(N, 4, ERROR);
            if ERROR then
               raise ENTRY_ERROR;
            end if;
            exit;
         exception
            when ENTRY_ERROR =>
               --
               CURSOR_TO(3, 1);
               ERASE_LINE;
               PUT("Please re-enter four digit Hex number again, carefully:
");
         end;
      end loop;
      CURSOR_TO(5, 1);
      PUT("You entered Hex ");
      HEX_PRINT(N, 4);
      PUT(" which is ");
      PUT(N, 3);
      PUT(" Decimal");
      NEW_LINE;
      --
      VOLTAGE := CONVERT(LONG_INTEGER(N));
      PUT(" This Value = ");
      PUT(VOLTAGE, 2, 3, 0);
      PUT(" Volts");
      NEW_LINE;
      --
      PUT(" Again? (y or n) ");
      GET(C);
      SKIP_LINE;
      exit when C /= 'y';
   end loop;

end Input_Hex_Number;


-- 
-----------------------------------------------------------------------------
-- Jerry Petrey                                                
-- Senior Principal Systems Engineer - Navigation, Guidance, & Control
-- Raytheon Missile Systems          - Member Team Ada & Team Forth
-- NOTE: please remove <NOSPAM> in email address to reply                  
-----------------------------------------------------------------------------



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

end of thread, other threads:[~2001-12-11 16:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-11  0:28 Error checking for type incompatibility Ben
2001-12-11  0:49 ` Mark Lundquist
2001-12-11  7:35 ` Preben Randhol
2001-12-11 16:31 ` Jerry Petrey

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