On 20-Apr-16 15:35, Gerald Wiltse wrote:
I re-arranged it as follows. Does this seem preferable from a performance perspective?.There will be about an 8:1 ratio... (8 matches of this[tmpKey] = v to every 1 exception which hits the catch which needs to be parsed.

                try {
                    this[tmpKey] = v
                } catch (GroovyCastException e) {
                    this[tmpKey] = new GroovyShell().parse(v).run()
                }

It looks tempting, but someone reading this code in 3 years will be like: WTF?!? Did you read Bloch: Effective Java? It has a chapter on Exceptions and how you should NOT use them. I'd guess this code of yours would be a good example for that chapter. When you say you have a form input for properties, you imply that NOT every valid groovy expression is a valid input.. Then why not just work off all the possible cases?

Felix

Reply via email to