sp00m
sp00m

Reputation: 48837

Does HttpServletResponse#sendError() ever throw an IOException?

The doc explains that the HttpServletResponse#sendError() method throws an IOException if an input or output exception occurs (DRY ;).

I couldn't find any scenario that makes this method throw that exception, is there any?

Upvotes: 1

Views: 1492

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 280168

HTTP is sent over TCP so you can safely assume that somewhere in the underlying HttpServletRequest and HttpServletResponse there is a SocketInputStream and a SocketOutputStream.

If a user closes their browser or the network goes down client-side or server-side, then the server won't be able to receive requests or send responses. If the disconnection happens while the server was in the process of sendError(), then an IOException will occur while writing to the SocketOutputStream.

Upvotes: 7

Related Questions