blob: 4d8881c68324ec9736eaa392ac8a8fbd0b3a7df2 [file] [log] [blame]
San Mehat4c27e0e2010-01-29 05:22:17 -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 com.android.server;
18
Jeff Sharkey31c6e482011-11-18 17:09:01 -080019import android.os.Parcel;
20
San Mehat4c27e0e2010-01-29 05:22:17 -080021/**
Jeff Sharkey31c6e482011-11-18 17:09:01 -080022 * An exception that indicates there was an error with a
23 * {@link NativeDaemonConnector} operation.
San Mehat4c27e0e2010-01-29 05:22:17 -080024 */
Jeff Sharkey31c6e482011-11-18 17:09:01 -080025public class NativeDaemonConnectorException extends Exception {
San Mehatec4caa02010-02-03 10:48:21 -080026 private String mCmd;
Jeff Sharkey31c6e482011-11-18 17:09:01 -080027 private NativeDaemonEvent mEvent;
San Mehat4c27e0e2010-01-29 05:22:17 -080028
Jeff Sharkey31c6e482011-11-18 17:09:01 -080029 public NativeDaemonConnectorException(String detailMessage) {
30 super(detailMessage);
San Mehat4c27e0e2010-01-29 05:22:17 -080031 }
32
Jeff Sharkey31c6e482011-11-18 17:09:01 -080033 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 + "'");
San Mehatec4caa02010-02-03 10:48:21 -080039 mCmd = cmd;
Jeff Sharkey31c6e482011-11-18 17:09:01 -080040 mEvent = event;
San Mehat4c27e0e2010-01-29 05:22:17 -080041 }
42
43 public int getCode() {
Daniel 2 Olofsson878b4552013-01-17 12:05:34 +010044 return mEvent != null ? mEvent.getCode() : -1;
San Mehat4c27e0e2010-01-29 05:22:17 -080045 }
San Mehatec4caa02010-02-03 10:48:21 -080046
47 public String getCmd() {
48 return mCmd;
49 }
Jeff Sharkey31c6e482011-11-18 17:09:01 -080050
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 }
San Mehat4c27e0e2010-01-29 05:22:17 -080058}