comp.lang.ada
 help / color / mirror / Atom feed
From: Dave <davedave@io.com>
Subject: Re: Help with Exceptions! (fwd)
Date: 1996/05/08
Date: 1996-05-08T00:00:00+00:00	[thread overview]
Message-ID: <Pine.BSI.3.91.960508012641.2120A-100000@pentagon.io.com> (raw)



There must be something wrong with my provider's news server.  Once 
again, a post did not "take" the first time that I sent it.  Hopefully, 
everything will work this time.

---------- Forwarded message ----------

Robert Gelb wrote:
> 
> I am doing a homework assignment in ADA and I am confused by the
> exceptions.  My question is this: when I catch an error with the
> exception, how can I go back to statement where the error occured (or the
> statement next to it)?
> I know in Visual Basic you can do a 'resume next' statement which returns
> you to the statement next to the one where the error occured
> 
> VB:
> sub test()
>         dim x as integer
>         on error goto ErrHandler
>         x = 1000000     'error occurs here
>         x = 3           'resume next returns the
>                         'execution here
>         Exit sub
> ErrHandler:
> resume next     'return execution
> end sub
> 
> ADA:
> procedure test is
>         x:integer;
> begin
>         x:=10000000;
>         x:=3;
> exception
>         when CONSTRAINT_ERROR=>
>                 put("Error");
>                 --how can I go back to 'x:=3' statement
> end test;
> Bob --

I have not tried this, and I do *not* recommend this (See my note below.), 
but it should work.  You can put a goto in the exception part of a block as 
long as you leave the block which raised the exception.

procedure test is
        x:integer ;
begin
	begin
	        x := 10000000 ;
        exception
		when CONSTRAINT_ERROR =>
			goto Next_Block ;
	end ;
<<Next_Block>>
	begin
		x := 3 ;
        exception
		when CONSTRAINT_ERROR =>
			RETURN ;
	end ;
	RETURN ;
end test;

Please note that this code is *UGLY*.  Generally, when programming in Ada, 
if you produce ugly code, that is a sign that there is a better solution to 
your problem.  Many Ada programmers produce ugly code by abusing Ada's 
excellent exception handling facilities, so you might want to reconsider 
your approach.

-- Dave Jones
davedave@io.com





             reply	other threads:[~1996-05-08  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-08  0:00 Dave [this message]
1996-05-08  0:00 ` Help with Exceptions! (fwd) Ray Blaak
replies disabled

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