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
17package com.android.server;
18
19import android.os.Parcel;
20
21/**
22 * An exception that indicates there was an error with a
23 * {@link NativeDaemonConnector} operation.
24 */
25public class NativeDaemonConnectorException extends Exception {
26    private String mCmd;
27    private NativeDaemonEvent mEvent;
28
29    public NativeDaemonConnectorException(String detailMessage) {
30        super(detailMessage);
31    }
32
33    public NativeDaemonConnectorException(String detailMessage, Throwable throwable) {
34        super(detailMessage, throwable);
35    }
36
37    public NativeDaemonConnectorException(String cmd, NativeDaemonEvent event) {
38        super("command '" + cmd + "' failed with '" + event + "'");
39        mCmd = cmd;
40        mEvent = event;
41    }
42
43    public int getCode() {
44        return mEvent != null ? mEvent.getCode() : -1;
45    }
46
47    public String getCmd() {
48        return mCmd;
49    }
50
51    /**
52     * Rethrow as a {@link RuntimeException} subclass that is handled by
53     * {@link Parcel#writeException(Exception)}.
54     */
55    public IllegalArgumentException rethrowAsParcelableException() {
56        throw new IllegalStateException(getMessage(), this);
57    }
58}
59