1 /* 2 * Copyright (C) 2007 Esmertec AG. 3 * Copyright (C) 2007 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.im.engine; 19 20 /** 21 * A generic exception that is thrown by the IM engine. If it's caused by an 22 * error condition returned by the IM server, an IMError is associated with 23 * it. 24 */ 25 public class ImException extends Exception { 26 private ImErrorInfo mError; 27 28 /** 29 * Creates a new ImException with the specified detail message. 30 * 31 * @param message the detail message. 32 */ 33 public ImException(String message) { 34 super(message); 35 } 36 37 /** 38 * Creates a new ImException with the IMError which was the cause of the 39 * exception. 40 * 41 * @param error the cause of the exception. 42 */ 43 public ImException(ImErrorInfo error) { 44 super(error.getDescription()); 45 mError = error; 46 } 47 48 /** 49 * Creates a new ImException with the specified cause. 50 * 51 * @param cause the cause. 52 */ 53 public ImException(Throwable cause) { 54 super(cause); 55 } 56 57 /** 58 * Creates a new ImException with the specified detail message and cause. 59 * 60 * @param message the detail message. 61 * @param cause the cause. 62 */ 63 public ImException(String message, Throwable cause) { 64 super(message, cause); 65 } 66 67 /** 68 * Creates a new ImException with specified IM error code and description 69 * 70 * @param imErrorCode 71 * @param string 72 */ 73 public ImException(int imErrorCode, String description) { 74 this(new ImErrorInfo(imErrorCode, description)); 75 } 76 77 /** 78 * Gets the IMError which caused the exception or <code>null</code> if 79 * there isn't one. 80 * 81 * @return the IMError which caused the exception. 82 */ 83 public ImErrorInfo getImError() { 84 return mError; 85 } 86 87 public void printStackTrace() { 88 System.err.println("ImError: " + mError); 89 super.printStackTrace(); 90 } 91 } 92