1 /*
2  * Copyright (C) 2019 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 com.android.server.soundtrigger_middleware;
18 
19 import android.annotation.NonNull;
20 
21 /**
22  * This exception represents a fault which:
23  * <ul>
24  * <li>Could not have been anticipated by a caller (i.e. is not a violation of any preconditions).
25  * <li>Is guaranteed to not have been caused any meaningful state change in the callee. The caller
26  *     may continue operation as if the call has never been made.
27  * </ul>
28  * <p>
29  * Some recoverable faults are permanent and some are transient / circumstantial, the specific error
30  * code can provide more information about the possible recovery options.
31  * <p>
32  * The reason why this is a RuntimeException is to allow it to go through interfaces defined by
33  * AIDL, which we have no control over.
34  *
35  * @hide
36  */
37 public class RecoverableException extends RuntimeException {
38     public final int errorCode;
39 
RecoverableException(int errorCode, @NonNull String message)40     public RecoverableException(int errorCode, @NonNull String message) {
41         super(message);
42         this.errorCode = errorCode;
43     }
44 
RecoverableException(int errorCode)45     public RecoverableException(int errorCode) {
46         this.errorCode = errorCode;
47     }
48 
49     @Override
toString()50     public @NonNull String toString() {
51         return super.toString() + " (code " + errorCode + ")";
52     }
53 }
54