xsharp.eu • How to replace BEGIN SEQUENCE...BREAK...RECOVER for own errors?
Page 1 of 1

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

Posted: Wed Sep 05, 2018 5:52 am
by kitz
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

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

Posted: Wed Sep 05, 2018 6:12 am
by lumberjack
Hi Kurt
Try:

Code: Select all

TRY
  <Statements>
CATCH oEx AS Exception
  THROW Exception{oEx:Message}
FINALY
  lOk := TRUE/FALSE
END TRY
HTH,

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

Posted: Wed Sep 05, 2018 6:27 am
by kitz
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

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

Posted: Wed Sep 05, 2018 7:20 am
by lumberjack
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:

Code: Select all

if x <> y
  lOk := FALSE
  THROW Exception{"Message"}
endif
You can also do it like this:

Code: Select all

TRY
  if x <> y
    THROW Exception{"Message"}
  endif
CATCH oEx AS Exception // THROW will be catch by this
    lOk := FALSE
END TRY
Regards,

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

Posted: Wed Sep 05, 2018 8:56 am
by kitz
Ok, thanks, that's what I have missed.