Reputation: 3885
When I try to catch an Exception in a controller method I could not catch SocketException. The controller action looks like:
def updateDeviceStartV1() {
try {
...
response.status = 200;
response.setContentType("application/octet-stream")
response.outputStream << responseService.encryptedResponse // byte[]
}
catch(Exception e) {
log.error "Server faced unexpected exception", e
response.status = 500;
...
}
The SocketException is thrown by line "response.outputStream << responseService.encryptedResponse" because the client unexpectedly close the connection. Nevertheless, this exception is not catched and the console receives standard exception display...
Am I doing something wrong?
Upvotes: 2
Views: 1494
Reputation: 3407
I think that if the method where the exception is raised doesn't throw the exception explicitly (with a throws in the signature), it will be thrown as an UndeclaredThrowableException. Then the type in your catch just doesn't match it. Try catching SocketException instead. Or if you can just catch them all using catch(all)
.
Oh, take a look at this.
Upvotes: 4