From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3fa706d5ad40e71c,start X-Google-Attributes: gid103376,public From: Dave Subject: Re: Help with Exceptions! (fwd) Date: 1996/05/08 Message-ID: #1/1 X-Deja-AN: 153680087 organization: Illuminati Online content-type: TEXT/PLAIN; charset=US-ASCII mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-05-08T00:00:00+00:00 List-Id: 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 ; <> 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