    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     *  contributor license agreements.  See the NOTICE file distributed with
    004     *  this work for additional information regarding copyright ownership.
    005     *  The ASF licenses this file to You under the Apache License, Version 2.0
    006     *  (the "License"); you may not use this file except in compliance with
    007     *  the License.  You may obtain a copy of the License at
    008     *
    009     *      http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     *  Unless required by applicable law or agreed to in writing, software
    012     *  distributed under the License is distributed on an "AS IS" BASIS,
    013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     *  See the License for the specific language governing permissions and
    015     *  limitations under the License.
    016     *
    017     */
    018
    019    package org.apache.commons.exec;
    020
    021    import java.io.IOException;
    022
    023    /**
    024     * An exception indicating that the executing a subprocesses failed.
    025     */
    026    public class ExecuteException extends IOException {
    027
    028        /**
    029         * Comment for <code>serialVersionUID</code>.
    030         */
    031        private static final long serialVersionUID = 3256443620654331699L;
    032
    033            /**
    034             * The underlying cause of this exception.
    035             */
    036            private final Throwable cause;
    037
    038            /**
    039             * The exit value returned by the failed process
    040             */
    041            private final int exitValue;
    042
    043        /**
    044         * Construct a new exception with the specified detail message.
    045         *
    046         * @param message
    047         *            The detail message
    048         * @param exitValue The exit value
    049         */
    050        public ExecuteException(final String message, int exitValue) {
    051            super(message + "(Exit value: " + exitValue + ")");
    052            this.cause = null;
    053            this.exitValue = exitValue;
    054        }
    055
    056        /**
    057         * Construct a new exception with the specified detail message and cause.
    058         *
    059         * @param message
    060         *            The detail message
    061         * @param exitValue The exit value
    062         * @param cause
    063         *            The underlying cause
    064         */
    065        public ExecuteException(final String message, int exitValue, final Throwable cause) {
    066            super(message + " (Exit value: " + exitValue + ". Caused by " + cause + ")");
    067            this.cause = cause; // Two-argument version requires JDK 1.4 or later
    068            this.exitValue = exitValue;
    069        }
    070
    071        /**
    072         * Return the underlying cause of this exception (if any).
    073         */
    074        public Throwable getCause() {
    075            return (this.cause);
    076        }
    077
    078        /**
    079         * Gets the exit value returned by the failed process
    080         * @return The exit value
    081         */
    082        public int getExitValue() {
    083            return exitValue;
    084        }
    085    }