I'm trying to catch an exception between two services but the catch code is unreachable. Does any one knows why?
Controller:
def controllerMethod() {
try {
service1.execute()
} catch(CustomException ce) {
// unreachable code
}
}
Service 1:
def service2
def service1Method() {
try {
service2.execute()
} catch(CustomException ce) {
// unreachable code
throw ce
}
}
Service 2:
def service2Method() {
throw new CustomException("exception")
}
Exception:
class CustomException extends Exception {
CustomException(String message){
super(message)
}
}
Running Sample: https://bitbucket.org/victor-giacomo/grails-exception-propagation/src/master/
See the project at github.com/jeffbrown/victorsoaresexception.
grails-app/services/victorsoaresexception/Service1Service.groovy
grails-app/services/victorsoaresexception/Service2Service.groovy
grails-app/controllers/victorsoaresexception/DemoController.groovy
That all appears to work: