Java Exception throw your own exception
public class Main { static Object chatServer = null; public static void main(String[] args) { try {// w w w . j a v a 2 s . c o m sendChat("Hello, how are you?"); } catch (ConnectionUnavailableException e) { System.out.println("Got a connection unavailable Exception!"); } disconnectChatServer(chatServer); } private static void disconnectChatServer(Object chatServer) { if (chatServer == null) throw new IllegalChatServerException("Chat server is empty"); } private static void sendChat(String chatMessage) throws ConnectionUnavailableException { if (chatServer == null) throw new ConnectionUnavailableException("Can't find the chat server"); } } class ConnectionUnavailableException extends Exception { ConnectionUnavailableException(String message) { super(message); } } class IllegalChatServerException extends RuntimeException { IllegalChatServerException(String message) { super(message); } }