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