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 /** @hide */ RemoteException(Throwable cause)41 public RemoteException(Throwable cause) { 42 this(cause.getMessage(), cause, true, false); 43 } 44 45 /** 46 * Rethrow this as an unchecked runtime exception. 47 * <p> 48 * Apps making calls into other processes may end up persisting internal 49 * state or making security decisions based on the perceived success or 50 * failure of a call, or any default values returned. For this reason, we 51 * want to strongly throw when there was trouble with the transaction. 52 * 53 * @throws RuntimeException 54 */ 55 @NonNull rethrowAsRuntimeException()56 public RuntimeException rethrowAsRuntimeException() { 57 throw new RuntimeException(this); 58 } 59 60 /** 61 * Rethrow this exception when we know it came from the system server. This 62 * gives us an opportunity to throw a nice clean 63 * {@link DeadSystemException} signal to avoid spamming logs with 64 * misleading stack traces. 65 * <p> 66 * Apps making calls into the system server may end up persisting internal 67 * state or making security decisions based on the perceived success or 68 * failure of a call, or any default values returned. For this reason, we 69 * want to strongly throw when there was trouble with the transaction. 70 * 71 * @throws RuntimeException 72 */ 73 @NonNull rethrowFromSystemServer()74 public RuntimeException rethrowFromSystemServer() { 75 if (this instanceof DeadObjectException) { 76 throw new RuntimeException(new DeadSystemException()); 77 } else { 78 throw new RuntimeException(this); 79 } 80 } 81 } 82