I have a method abc() in which the request is forwarded to other controller actions based on some condition. Is it possible to catch exception thrown in oneMethod of class oneController inside catch of abc() method? I am putting code for reference –
Main method –>
<code>Class abc{
void abc(int findMethod) {
try {
if (params.findMethod == 1) {
forward(controller: 'oneController', action: 'oneMethod')
return
} else {
forward(controller: 'twoController', action: 'twoMethod')
return
}
} catch (Exception ex) {
log.error("Error while downloading ICSR Report", ex)
}
}
}
</code>
<code>Class abc{
void abc(int findMethod) {
try {
if (params.findMethod == 1) {
forward(controller: 'oneController', action: 'oneMethod')
return
} else {
forward(controller: 'twoController', action: 'twoMethod')
return
}
} catch (Exception ex) {
log.error("Error while downloading ICSR Report", ex)
}
}
}
</code>
Class abc{
void abc(int findMethod) {
try {
if (params.findMethod == 1) {
forward(controller: 'oneController', action: 'oneMethod')
return
} else {
forward(controller: 'twoController', action: 'twoMethod')
return
}
} catch (Exception ex) {
log.error("Error while downloading ICSR Report", ex)
}
}
}
Called Method –>
<code>Class oneController {
void oneMethod() {
if (someCondition) {
throw new ArithmeticException("no data found")
}
}
}
</code>
<code>Class oneController {
void oneMethod() {
if (someCondition) {
throw new ArithmeticException("no data found")
}
}
}
</code>
Class oneController {
void oneMethod() {
if (someCondition) {
throw new ArithmeticException("no data found")
}
}
}
I don’t want to change the code for oneMethod or twoMethod. Can I somehow catch these exceptions inside abc() ?