blob: 98c66d1beaf47f206b4c49dff9e9770296950a75 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.os;
Jeff Sharkeyf8880562016-02-26 13:03:01 -070018
Roshan Pius148e86e2019-11-13 12:40:01 -080019import android.annotation.NonNull;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.util.AndroidException;
21
22/**
23 * Parent exception for all Binder remote-invocation errors
24 */
25public class RemoteException extends AndroidException {
26 public RemoteException() {
27 super();
28 }
Jeff Brown0bde66a2011-11-07 12:50:08 -080029
30 public RemoteException(String message) {
31 super(message);
32 }
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070033
Fyodor Kupolova81b8c02017-11-13 15:51:03 -080034 /** @hide */
35 public RemoteException(String message, Throwable cause, boolean enableSuppression,
36 boolean writableStackTrace) {
37 super(message, cause, enableSuppression, writableStackTrace);
38 }
39
Roshan Pius148e86e2019-11-13 12:40:01 -080040 /**
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.
Roshan Pius866e9112019-11-20 14:47:51 -080047 *
48 * @throws RuntimeException
Roshan Pius148e86e2019-11-13 12:40:01 -080049 */
50 @NonNull
Jeff Sharkey3a44f3f2014-04-28 17:36:31 -070051 public RuntimeException rethrowAsRuntimeException() {
52 throw new RuntimeException(this);
53 }
Jeff Sharkeyf8880562016-02-26 13:03:01 -070054
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.
Roshan Pius866e9112019-11-20 14:47:51 -080065 *
66 * @throws RuntimeException
Jeff Sharkeyf8880562016-02-26 13:03:01 -070067 */
Roshan Pius148e86e2019-11-13 12:40:01 -080068 @NonNull
Jeff Sharkeyf8880562016-02-26 13:03:01 -070069 public RuntimeException rethrowFromSystemServer() {
70 if (this instanceof DeadObjectException) {
71 throw new RuntimeException(new DeadSystemException());
72 } else {
73 throw new RuntimeException(this);
74 }
75 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076}