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 019package org.apache.commons.exec; 020 021import java.io.IOException; 022 023/** 024 * An exception indicating that the executing a subprocesses failed. 025 * 026 * @version $Id: ExecuteException.java 1636056 2014-11-01 21:12:52Z ggregory $ 027 */ 028public class ExecuteException extends IOException { 029 030 /** 031 * Comment for {@code serialVersionUID}. 032 */ 033 private static final long serialVersionUID = 3256443620654331699L; 034 035 /** 036 * The underlying cause of this exception. 037 */ 038 private final Throwable cause; 039 040 /** 041 * The exit value returned by the failed process 042 */ 043 private final int exitValue; 044 045 /** 046 * Construct a new exception with the specified detail message. 047 * 048 * @param message 049 * The detail message 050 * @param exitValue The exit value 051 */ 052 public ExecuteException(final String message, final int exitValue) { 053 super(message + " (Exit value: " + exitValue + ")"); 054 this.cause = null; 055 this.exitValue = exitValue; 056 } 057 058 /** 059 * Construct a new exception with the specified detail message and cause. 060 * 061 * @param message 062 * The detail message 063 * @param exitValue The exit value 064 * @param cause 065 * The underlying cause 066 */ 067 public ExecuteException(final String message, final int exitValue, final Throwable cause) { 068 super(message + " (Exit value: " + exitValue + ". Caused by " + cause + ")"); 069 this.cause = cause; // Two-argument version requires JDK 1.4 or later 070 this.exitValue = exitValue; 071 } 072 073 /** 074 * Return the underlying cause of this exception (if any). 075 */ 076 @Override 077 public Throwable getCause() { 078 return this.cause; 079 } 080 081 /** 082 * Gets the exit value returned by the failed process 083 * @return The exit value 084 */ 085 public int getExitValue() { 086 return exitValue; 087 } 088}