Using eval()

I want to give users the freedom to make their own calculations.
They will put the calculations into a field…for example:

5*10/(8-5)

I then want to use eval(field) to perform the calculation in a method.
It works…but is there a way to examine first the calculation if it’s errorfree.
Becoz when I eval( ‘5*10/8-5)’ ) it encounters an error (missing a ‘(’ )
and the method quits.

Is there an error-catching way for eval() ?

Didn’t test this but what if you put the eval in a Try-Catch block ?

I tried

var evalstring = '2*(2+1';
try {
	eval(evalstring);
} catch( myError ) {
	application.output(myError);
	return;
}
application.output (eval(evalstring));

But Servoy stops at line 3 with a Syntax error

Because of the closing bracket? ```
‘2*(2+1’

IT2Be:
Because of the closing bracket? ```
‘2*(2+1’

Yes…I want to catch that error…

Have you tried googling on “javascript eval trap error”?

Fourth entry I got was: “JavaScript Exception Handling”
It goes into details about trapping different kind of errors, also eval() errors.

Haven’t tried it, but might help you…

Ok…I figured it out…
I was running Servoy in Debug-mode…
When running is Debug-mode…the try-catch thing doesn’t work
When you run normally…it works like a charm…

In Servoy 3.0 we made it possible to control this behaviour by introducing the “exception break” checkbox in the debugger