/*
 * Copyright (C) 2026 UBports Foundation.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <boost/exception_ptr.hpp>

#include <stdexcept>

// Provider errors travel as values, so EXPECT_THROW has nothing to catch:
// rethrow the pointer to check its type and return the exception for
// assertions.
template <typename E>
E expect_throw(boost::exception_ptr p)
{
    try
        { boost::rethrow_exception(p); }
    catch (E const& e)
        { return e; }
    throw std::runtime_error("No exception thrown, or wrong type");
}
