Wednesday, April 21, 2010

Grails save() dynamic method requires exception throwing to be enabled explicitly

http://www.grails.org/doc/latest/ref/Domain%20Classes/save.html:
Check out the failOnError option.


if( !b.save() ) {
   b.errors.each {
        println it
   }
}
OR
try{
b.save(failOnError :true)
}catch(ValidationException e){
//handle exception
}
However I could't find any ValidationException class in the package grails.validation of grails-1.2.1.
So went for the b.errors.each approach.

1 comment:

  1. Thanks for this post...
    Are you aware of any such feature for dynamic get() domain method?
    All I want is an exception to be thrown when there is no object for the passed id

    ReplyDelete