Specifications

Sun Services
Java™ Programming Language
Module 8, slide 18 of 25
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Handling a User-Defined Exception
A method can throw a user-defined, checked exception:
1 public void connectMe(String serverName)
2 throws ServerTimedOutException {
3 boolean successful;
4 int portToConnect = 80;
5
6 successful = open(serverName, portToConnect);
7
8 if ( ! successful ) {
9 throw new ServerTimedOutException("Could not connect",
10 portToConnect);
11 }
12 }