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    package org.apache.commons.pipeline;
019    
020    import org.apache.commons.pipeline.StageDriver.State;
021    
022    /**
023     * This exception class is used to store detailed information about
024     * a failure in the processing step of a stage including the failing data,
025     * the driver state at the time of failure, and any exceptions encountered.
026     */
027    public class ProcessingException extends StageException {
028        private final Object data;
029        private final State driverState;
030        
031        /**
032         * Creates a new instance of ProcessingException
033         *
034         * @param data The object which was not able to be processed.
035         * @param throwable The exception that occurred.
036         */
037        public ProcessingException(Stage stage, Throwable cause, Object data, State driverState) {
038            super(stage, cause);
039            this.data = data;
040            this.driverState = driverState;
041        }
042        
043        /**
044         * Returns the object that was being processed at the time of failure.
045         * @return The object which was not able to be processed.
046         */
047        public Object getData(){
048            return this.data;
049        }
050        
051        /**
052         * Returns the saved driver state at the time of processing failure.
053         * @return the driver state at the time of processing failure.
054         */
055        public State getDriverState() {
056            return this.driverState;
057        }
058    }