Ring/Lessons/Eval() and Debugging

Eval and Debugging
In this chapter we are going to learn about


 * Error Handling using Try/Catch/Done


 * Eval function


 * Raise function


 * Assert function

Try/Catch/Done
Syntax:

The statements in the Try block will be executed, if any error happens then the statements in the catch block will be executed.

Inside the catch block we can use the variable cCatchError to get the error message

Example:

Output:

Eval Function
We can execute code during the runtime from string using the Eval function

Syntax:

Example:

Output:

Raise Function
We can raise an exception using the Raise function

Syntax:

The function will display the error message then end the execution of the program.

We can use Try/Catch/Done to avoid exceptions generated by raise function.

Example:

if nMode < 0 or nMode > 5 raise("Error : nMode not in the range 1:4") ok

Output:

Example:

Output:

Assert Function
We can use the Assert function to test conditions before executing the code

If the test fail the program will be terminated with an error message contains the assert condition.

Syntax:

Example:

Output: