Specifications

Sun Services
Java™ Programming Language
Module 8, slide 19 of 25
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Handling a User-Defined Exception
Another method can use a try-catch block to capture
user-defined exceptions:
1 public void findServer() {
2 try {
3 connectMe(defaultServer);
4 } catch (ServerTimedOutException e) {
5 System.out.println("Server timed out, trying alternative");
6 try {
7 connectMe(alternativeServer);
8 } catch (ServerTimedOutException e1) {
9 System.out.println("Error: " + e1.getMessage() +
10 " connecting to port " + e1.getPort());
11 }
12 }
13 }