If formula errors occur during calculation of formulas for mechatronic objects, the script is usually aborted. To avoid this and to handle the formula error within the script, the 'EvaluationException' is caught:
package com.mind8.nativescript.example;
import org.foederal.eobroker.core.IEngineeringObject;
import org.foederal.core.IExecutionEnvironment;
import com.mind8.expressionparser.EvaluationException;
import com.mind8.mechatronic.skill.eos.MechatronicObject;
import com.mind8.mechatronic.skill.methods.AbstractNativeMethod;
public class ExampleEvaluationExceptionImpl extends AbstractNativeMethod
public ExampleEvaluationExceptionImpl(IExecutionEnvironment execEnv)
{
super(execEnv);
}
@Override
public Object perform(IEngineeringObject self,Object[] objects)
{
try
{
((MechatronicObject) objects[0]).evaluate("mc.§Deckblatt.$Anlage");
}
catch(EvaluationException e)
{
//reagieren auf die Exception z.B. in die Console schreiben,
// Default-Werte initialisieren, etc
}
return null;
}
import com.mind8.expressionparser.EvaluationException;
Object anlage;
String formel = 'mc.§Deckblatt.$Anlage';
try
{
anlage = self.evaluate(formel);
}
catch(EvaluationException e)
{
//reagieren auf die Exception z.B. in die Console schreiben,
UserMessageCollector.addError(LIBRARY,self,null,'Skript',"Konnte Formel '$formel' nicht auswerten", e);
// Default-Werte initialisieren, etc
anlage = null;
}
if (anlage == null)
{
/* ggf. einen passenden Wert zurückliefern, falls die Methode einen Rückgabetyp hat.*/
return;
}