Using exit command while in a if or when statement.

Guest
Hi!

I'm trying to write an ocean script that will exit if certain error is encountered.
I'm using the following:


when(variable==nil
error("The data is unavailable further simulation has been canceled")
exit
)

That is just a segment of the code and it includes an exit statement at the end of the ocean file. Although I have several of those verifications the error message is correctly seen in the terminal although the program is not ending at that moment.
I'm running and debugging the ocean script by doing:

ocean < file.ocn

And then looking at the messages in the terminal window. I don't know what I'm doing wrong.

Thanks in advance for your help,
Fernando
 
El viernes, 13 de junio de 2014 06:11:53 UTC-5, Andrew Beckett escribió:
On 06/12/14 21:11, Fernando wrote:



when(variable==nil error("The data is unavailable further simulation

has been canceled") exit )





That won't work, because error() will cause the code to be aborted at

that point and so it will never get to the exit().



You could just use:



fprintf(errport "*Error* The data is unavailable...\n")

exit()



You could just printf too, but I picked fprintf as that way it can print

to the same port as error() does.



You could also do:



errset(error("The data is unavailable ...") t)



too. This still calls error, but traps the error with the errset. The t

at the end stops it suppressing the error message.



Andrew.

Alright! Thank you very much! I used this version:

fprintf(errport "*Error* The data is unavailable...\n")
exit()

It worked great! I wasn't aware of the error() command aborting the code after its execution.

Thanks again and have a great day!
Fernando
 
On 06/12/14 21:11, ies.ferlavalle@gmail.com wrote:
when(variable==nil error("The data is unavailable further simulation
has been canceled") exit )

That won't work, because error() will cause the code to be aborted at
that point and so it will never get to the exit().

You could just use:

fprintf(errport "*Error* The data is unavailable...\n")
exit()

You could just printf too, but I picked fprintf as that way it can print
to the same port as error() does.

You could also do:

errset(error("The data is unavailable ...") t)

too. This still calls error, but traps the error with the errset. The t
at the end stops it suppressing the error message.

Andrew.
 

Welcome to EDABoard.com

Sponsor

Back
Top