Workshop: Throwing and Catching Exceptions

For this hour's workshop, you will create a class that uses exceptions to tell another class about an error that has taken place.

The classes in this workshop are HomePage, a class that represents a personal home page on the World Wide Web, and PageCatalog, an application that catalogs these pages.

Enter the text of Listing 18.4 in your text editor, saving it as HomePage.java when you're done.

Listing 18.4. The Full Text of HomePage.java
 1: import java.net.*; 2: 3: public class HomePage { 4: String owner; 5: URL address; 6: String category = "none"; 7: 8: public HomePage(String inOwner, String inAddress) 9: throws MalformedURLException { 10: 11: owner = inOwner; 12: address = new URL(inAddress); 13: ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.