Home | History | Annotate | Download | only in mail
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.email.mail;
     18 
     19 /**
     20  * This exception is used for most types of failures that occur during server interactions.
     21  *
     22  * Data passed through this exception should be considered non-localized.  Any strings should
     23  * either be internal-only (for debugging) or server-generated.
     24  *
     25  * TO DO: Does it make sense to further collapse AuthenticationFailedException and
     26  * CertificateValidationException and any others into this?
     27  */
     28 public class MessagingException extends Exception {
     29     public static final long serialVersionUID = -1;
     30 
     31     public static final int NO_ERROR = -1;
     32     /** Any exception that does not specify a specific issue */
     33     public static final int UNSPECIFIED_EXCEPTION = 0;
     34     /** Connection or IO errors */
     35     public static final int IOERROR = 1;
     36     /** The configuration requested TLS but the server did not support it. */
     37     public static final int TLS_REQUIRED = 2;
     38     /** Authentication is required but the server did not support it. */
     39     public static final int AUTH_REQUIRED = 3;
     40     /** General security failures */
     41     public static final int GENERAL_SECURITY = 4;
     42     /** Authentication failed */
     43     public static final int AUTHENTICATION_FAILED = 5;
     44     /** Attempt to create duplicate account */
     45     public static final int DUPLICATE_ACCOUNT = 6;
     46     /** Required security policies reported - advisory only */
     47     public static final int SECURITY_POLICIES_REQUIRED = 7;
     48    /** Required security policies not supported */
     49     public static final int SECURITY_POLICIES_UNSUPPORTED = 8;
     50    /** The protocol (or protocol version) isn't supported */
     51     public static final int PROTOCOL_VERSION_UNSUPPORTED = 9;
     52 
     53     protected int mExceptionType;
     54 
     55     public MessagingException(String message) {
     56         super(message);
     57         mExceptionType = UNSPECIFIED_EXCEPTION;
     58     }
     59 
     60     public MessagingException(String message, Throwable throwable) {
     61         super(message, throwable);
     62         mExceptionType = UNSPECIFIED_EXCEPTION;
     63     }
     64 
     65     /**
     66      * Constructs a MessagingException with an exceptionType and a null message.
     67      * @param exceptionType The exception type to set for this exception.
     68      */
     69     public MessagingException(int exceptionType) {
     70         super();
     71         mExceptionType = exceptionType;
     72     }
     73 
     74     /**
     75      * Constructs a MessagingException with an exceptionType and a message.
     76      * @param exceptionType The exception type to set for this exception.
     77      */
     78     public MessagingException(int exceptionType, String message) {
     79         super(message);
     80         mExceptionType = exceptionType;
     81     }
     82 
     83     /**
     84      * Return the exception type.  Will be OTHER_EXCEPTION if not explicitly set.
     85      *
     86      * @return Returns the exception type.
     87      */
     88     public int getExceptionType() {
     89         return mExceptionType;
     90     }
     91 }
     92