1 /*
2  * Copyright (C) 2015 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 package android.os;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 import android.annotation.SystemApi;
21 import android.ravenwood.annotation.RavenwoodKeepWholeClass;
22 
23 /**
24  * An exception specific to a service.
25  *
26  * <p>This exception includes an error code specific to the throwing
27  * service.  This is mostly used by system services to indicate
28  * domain specific error conditions.</p>
29  *
30  * <p>Since these exceptions are designed to be passed through Binder
31  * interfaces, and to be generated by native-code Binder services,
32  * they do not support exception chaining.</p>
33  *
34  * @hide
35  */
36 @SystemApi
37 @RavenwoodKeepWholeClass
38 public class ServiceSpecificException extends RuntimeException {
39     public final int errorCode;
40 
ServiceSpecificException(int errorCode, @Nullable String message)41     public ServiceSpecificException(int errorCode, @Nullable String message) {
42         super(message);
43         this.errorCode = errorCode;
44     }
45 
ServiceSpecificException(int errorCode)46     public ServiceSpecificException(int errorCode) {
47         this.errorCode = errorCode;
48     }
49 
50     @NonNull
51     @Override
toString()52     public String toString() {
53         return super.toString() + " (code " + errorCode + ")";
54     }
55 }
56