Groovy web console

subscribe to the feed Subscribe
to this


Published 3 weeks ago by MikeG
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
// based on
text = 'i am a ${interpolated} string'
interpolated = 'runtime'

engine = new groovy.text.SimpleTemplateEngine()
template = engine.createTemplate(text)

makeWithMap = template.make([interpolated : interpolated])
// these all work fine
println((String) makeWithMap)

println("done with makeWithMap")

try {
    // uncomment this for a sane outcome
    // x = 1/0
    makeWithBindingVariables = template.make(this.binding.variables)
    // this will produce output, but stop executing after:
    // these will NOT produce output, and will stop executing:
    println((String) makeWithBindingVariables)
} catch (Exception e) { // nothing is caught
    println("am dead ${e}")
} finally { // we never get here, either
    println("how did I break a finally block?")
// this won't be reached if any of the above are called
println("All done")