Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:55:05

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file corecel/io/LogContextException.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <exception>
0010 
0011 namespace celeritas
0012 {
0013 class OutputRegistry;
0014 
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Log an exception's context and optionally save to an output registry.
0018  *
0019  * Example:
0020  * \code
0021     CELER_TRY_HANDLE(step(), LogContextException{this->output_reg().get()});
0022    \endcode
0023  */
0024 struct LogContextException
0025 {
0026     void operator()(std::exception_ptr p);
0027 
0028     OutputRegistry* out{nullptr};
0029 };
0030 
0031 //---------------------------------------------------------------------------//
0032 /*!
0033  * Log any RichContextException and rethrow the embedded pointer.
0034  *
0035  * This is useful for unit tests and other situations where the nearest `catch`
0036  * does not use `std::rethrow_if_nested`.
0037  *
0038  * \code
0039  CELER_TRY_HANDLE(step(), log_context_exception);
0040    \endcode
0041  */
0042 inline void log_context_exception(std::exception_ptr p)
0043 {
0044     return LogContextException{}(p);
0045 }
0046 
0047 //---------------------------------------------------------------------------//
0048 }  // namespace celeritas