I have service class and I have one service :
class service {
def activate(def part1,def part2) {
//here I check whether the provided part1 and part2 are correct
//If so I open a keystore or else catch the exception. .
try {
//code goes here. . . .
}
catch(IOException e)
{
log.error("")
}
}
}
Now In my controller code I call this service. I want a way to know whether the activate service succeeds opening the keystore, with provided part1 and part2. Initially I added a boolean variable into try/catch block to get the status, but I guess thats the bad practice.
Apart from it, how do I get to know whether the active service succeeds or not?
Thanks in advance.
A couple of approaches you could take here:
activatecan throw an exception instead of just logging the error if opening the keystore fails (rather than just catching and logging the error). This depends on the specifics of your application though – is it actually an error case if the keystore is not opened? or is it possible/probably that a keystore may not be opened?You could have
activatereturn a boolean true/false and the caller of that method could check the return value ofactivate