// Reading a WWW page and using a try with more than one catch clause // Barry Cornelius, 23rd November 1999 import java.io. BufferedReader; import java.io. InputStream; import java.io. InputStreamReader; import java.io. IOException; import java.net. MalformedURLException; import java.util. Properties; import java.net. URL; public class WWWManyCatchClauses { public static void main(final String[] pArgs) { // you will need to uncomment the following three statements // if your access to the WWW is through a proxy machine // you will have to replace proxymachine.sitename.com // and 8080 with appropriate values for your site // final Properties tProperties = System.getProperties(); // tProperties.put("http.proxyHost", "proxymachine.sitename.com"); // tProperties.put("http.proxyPort", "8080"); final BufferedReader tKeyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.print("URL? "); String tUrlString = null; URL tUrl = null; InputStream tInputStream = null; try { tUrlString = tKeyboard.readLine(); tUrl = new URL(tUrlString); tInputStream = tUrl.openStream(); } catch(MalformedURLException pMalformedURLException) { System.out.println("MalformedURLException occurred"); System.exit(1); } catch(IOException pIOException) { System.out.println("IOException occurred"); System.exit(2); } final BufferedReader tWebPage = new BufferedReader(new InputStreamReader(tInputStream)); try { while (true) { String tLine = tWebPage.readLine(); if ( tLine == null ) { break; } System.out.println(tLine); } } catch(IOException pIOException) { System.out.println("IOException occurred later"); System.exit(3); } } }