Groovy has less ceremony than Java. That’s crystal-clear in exception handling. Java forces us to handle checked exceptions. Groovy does not force us to handle exceptions that we don’t want to handle or that are inappropriate at the current level of code. Any exception we don’t handle is automatically passed on to a higher level.
Although the distinction between checked exceptions and runtime exceptions in Groovy is blurred, GORM versions before 6.0.0 did not roll back transactions for checked Exceptions. However, they rollbacked transactions for runtime exceptions.
Grails 3.2.0 shipped with GORM 6.0.0. One of the changes introduced by GORM 6.0.0 is that if a transactional method throws an Exception (both checked or runtime exception), the transaction will automatically be rolled back. Thus, same behavior for checked and runtime exceptions as you may expect in Groovy.
The previous behavior is better illustrated with an example:
Given a Checked Exception
and a RuntimeException
and the next service:
The next specification passes for versions
of GORM 6.0.0 or beyond.