1 /*
2  * Copyright (C) 2006 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 android.os;
18 
19 import android.annotation.NonNull;
20 import android.util.AndroidException;
21 
22 /**
23  * Parent exception for all Binder remote-invocation errors
24  */
25 public class RemoteException extends AndroidException {
RemoteException()26     public RemoteException() {
27         super();
28     }
29 
RemoteException(String message)30     public RemoteException(String message) {
31         super(message);
32     }
33 
34     /** @hide */
RemoteException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)35     public RemoteException(String message, Throwable cause, boolean enableSuppression,
36             boolean writableStackTrace) {
37         super(message, cause, enableSuppression, writableStackTrace);
38     }
39 
40     /**
41      * Rethrow this as an unchecked runtime exception.
42      * <p>
43      * Apps making calls into other processes may end up persisting internal
44      * state or making security decisions based on the perceived success or
45      * failure of a call, or any default values returned. For this reason, we
46      * want to strongly throw when there was trouble with the transaction.
47      *
48      * @throws RuntimeException
49      */
50     @NonNull
rethrowAsRuntimeException()51     public RuntimeException rethrowAsRuntimeException() {
52         throw new RuntimeException(this);
53     }
54 
55     /**
56      * Rethrow this exception when we know it came from the system server. This
57      * gives us an opportunity to throw a nice clean
58      * {@link DeadSystemException} signal to avoid spamming logs with
59      * misleading stack traces.
60      * <p>
61      * Apps making calls into the system server may end up persisting internal
62      * state or making security decisions based on the perceived success or
63      * failure of a call, or any default values returned. For this reason, we
64      * want to strongly throw when there was trouble with the transaction.
65      *
66      * @throws RuntimeException
67      */
68     @NonNull
rethrowFromSystemServer()69     public RuntimeException rethrowFromSystemServer() {
70         if (this instanceof DeadObjectException) {
71             throw new RuntimeException(new DeadSystemException());
72         } else {
73             throw new RuntimeException(this);
74         }
75     }
76 }
77