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