    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 *      https://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
    035    /**
    036     * The list of causes.
    037     */
    038    private final List<? extends Throwable> causeList;
    039
    040    /**
    041     * Creates a new exception caused by a list of exceptions.
    042     *
    043     * @param causeList a list of cause exceptions.
    044     */
    045    public SQLExceptionList(final List<? extends Throwable> causeList) {
    046        super(String.format("%,d exceptions: %s", causeList == null ? 0 : causeList.size(), causeList),
    047                causeList == null ? null : causeList.get(0));
    048        this.causeList = causeList;
    049    }
    050
    051    /**
    052     * Gets the cause list.
    053     *
    054     * @return The list of causes.
    055     */
    056    public List<? extends Throwable> getCauseList() {
    057        return causeList;
    058    }
    059
    060}