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
018package org.apache.commons.exec;
019
020import java.io.IOException;
021
022/**
023 * An exception indicating that the executing a subprocesses failed.
024 */
025public class ExecuteException extends IOException {
026
027    /**
028     * Comment for {@code serialVersionUID}.
029     */
030    private static final long serialVersionUID = 3256443620654331699L;
031
032    /**
033     * The exit value returned by the failed process.
034     */
035    private final int exitValue;
036
037    /**
038     * Constructs a new exception with the specified detail message.
039     *
040     * @param message   The detail message.
041     * @param exitValue The exit value.
042     */
043    public ExecuteException(final String message, final int exitValue) {
044        super(message + " (Exit value: " + exitValue + ")");
045        this.exitValue = exitValue;
046    }
047
048    /**
049     * Constructs a new exception with the specified detail message and cause.
050     *
051     * @param message   The detail message.
052     * @param exitValue The exit value.
053     * @param cause     The underlying cause.
054     */
055    public ExecuteException(final String message, final int exitValue, final Throwable cause) {
056        super(message + " (Exit value: " + exitValue + ")", cause);
057        this.exitValue = exitValue;
058    }
059
060    /**
061     * Gets the exit value returned by the failed process.
062     *
063     * @return The exit value.
064     */
065    public int getExitValue() {
066        return exitValue;
067    }
068}