Wrap groovy script exceptions in a serializable Exception object

Fixes #6598