fbpx

How to replace BEGIN SEQUENCE...BREAK...RECOVER for own errors?

More
4 months 1 week ago #1 by Kurt Kitzberger
Hi!
In VO I used BREAK very often to 'jump to the end' if an error was detected from my own program, not only runtime errors.
I tried to use a switch which is set to false if an error occurs:
lok := true
if lOk
xxxx
if <some error>
cMsg = "..."
lOk := false
endif
endif
...
But in this construct I get errors for 'use of uninitialised variables' because the compiler doesn't know that if lOk is true, any initialisation is made.

In X# I use TRY ... CATCH... for Exceptions of .net and runtime, but don't know how to use RAISE and if this makes sense anyway.
Some guidance to the right track?

BR Kurt

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #2 by Johan Nel
Hi Kurt
Try:
TRY
  <Statements>
CATCH oEx AS Exception
  THROW Exception{oEx:Message}
FINALY
  lOk := TRUE/FALSE
END TRY
HTH,

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #3 by Kurt Kitzberger
Hi Jamal,
for me this looks like there is already an exception and it's thrown again...?
But my question is if I can create an exception myself if I detect an error e.g.
if x <> y
throw xxx
and what I have to take care of.
And if this makes sense.
BR Kurt

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #4 by Johan Nel
Hi Kurt,

kitz wrote: for me this looks like there is already an exception and it's thrown again...?
But my question is if I can create an exception myself if I detect an error e.g.
if x <> y
throw xxx
and what I have to take care of.

Yes you can:
if x <> y
  lOk := FALSE
  THROW Exception{"Message"}
endif
You can also do it like this:
TRY
  if x <> y
    THROW Exception{"Message"}
  endif
CATCH oEx AS Exception // THROW will be catch by this
    lOk := FALSE
END TRY

Regards,

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

More
4 months 1 week ago #5 by Kurt Kitzberger
Ok, thanks, that's what I have missed.

Please Log in or Create an account to join the conversation.