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

This forum is meant for questions and discussions about the X# language and tools
Post Reply
kitz
Posts: 87
Joined: Wed Nov 29, 2017 8:56 am

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

Post 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
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

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

Post 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,
______________________
Johan Nel
Boshof, South Africa
kitz
Posts: 87
Joined: Wed Nov 29, 2017 8:56 am

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

Post 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
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

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

Post 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,
______________________
Johan Nel
Boshof, South Africa
kitz
Posts: 87
Joined: Wed Nov 29, 2017 8:56 am

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

Post by kitz »

Ok, thanks, that's what I have missed.
Post Reply