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 */
017package org.apache.commons.dbcp2;
018
019import java.sql.SQLException;
020import java.util.List;
021
022/**
023 * An SQLException based on a list of Throwable causes.
024 * <p>
025 * The first exception in the list is used as this exception's cause and is accessible with the usual
026 * {@link #getCause()} while the complete list is accessible with {@link #getCauseList()}.
027 * </p>
028 *
029 * @since 2.7.0
030 */
031public class SQLExceptionList extends SQLException {
032
033    private static final long serialVersionUID = 1L;
034    private final List<? extends Throwable> causeList;
035
036    /**
037     * Creates a new exception caused by a list of exceptions.
038     *
039     * @param causeList a list of cause exceptions.
040     */
041    public SQLExceptionList(final List<? extends Throwable> causeList) {
042        super(String.format("%,d exceptions: %s", causeList == null ? 0 : causeList.size(), causeList),
043                causeList == null ? null : causeList.get(0));
044        this.causeList = causeList;
045    }
046
047    /**
048     * Gets the cause list.
049     *
050     * @return The list of causes.
051     */
052    public List<? extends Throwable> getCauseList() {
053        return causeList;
054    }
055
056}