O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling Network Errors

try {
											// connect to network host
											// perform network IO
											}
											catch (UnknownHostException ex) {
											System.err.println("Unknown host.");
											}
											catch (NoRouteToHostException ex) {
											System.err.println("Unreachable host.");
											}
											catch (ConnectException ex) {
											System.err.println("Connect refused.");
											}
											catch (IOException ex) {
											System.err.println(ex.getMessage());
											}

In this phrase, we illustrate the series of exceptions you should attempt to catch when performing network operations.

The first exception we try to catch is the UnknownHostException. This is a subclass of IOException and is thrown to indicate that the IP address of a host could not be determined.

NoRouteToHostException and the ConnectException are subclasses of SocketException. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required