How do I throw an exception?

Question

Just throw a new Exception("Xxx")? That gives me Unexpected type: java.lang.Exception. Is there some exception class I can use for this?

Answer

Use throwException(String errorMessage)

For details see: https://developer.pricefx.eu/pricefx-api/groovy/develop/net/pricefx/formulaengine/scripting/PublicGroovyAPI.html#throwException-java.lang.String-

A calculation logic can stop its execution and fail by throwing an exception, for example:

if (api.userEntry("margin") <0) then api.throwException("I won't let you go bankrupt") else price=cost+margin

Found an issue in documentation? Write to us.