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