comp.lang.ada
 help / color / mirror / Atom feed
* Re: Help with Exceptions! (fwd)
@ 1996-05-08  0:00 Dave
  1996-05-08  0:00 ` Ray Blaak
  0 siblings, 1 reply; 2+ messages in thread
From: Dave @ 1996-05-08  0:00 UTC (permalink / 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





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

end of thread, other threads:[~1996-05-08  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-08  0:00 Help with Exceptions! (fwd) Dave
1996-05-08  0:00 ` Ray Blaak

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