Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:48

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file corecel/io/ExceptionOutput.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <exception>
0011 #include <memory>
0012 #include <string>
0013 
0014 #include "corecel/sys/TypeDemangler.hh"
0015 
0016 #include "OutputInterface.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Save an exception to the 'result' for diagnostic output.
0023  *
0024  * \code
0025     try
0026     {
0027         ...
0028     }
0029     catch (...)
0030     {
0031         output_mgr.insert(std::make_shared<ExceptionOutput>(
0032             std::current_exception()));
0033     }
0034    \endcode
0035  */
0036 class ExceptionOutput final : public OutputInterface
0037 {
0038   public:
0039     // Construct with an exception pointer
0040     explicit ExceptionOutput(std::exception_ptr e);
0041 
0042     // Protected destructor
0043     ~ExceptionOutput();
0044 
0045     // Category of data to write
0046     Category category() const final { return Category::result; }
0047 
0048     // Key for the entry inside the category.
0049     std::string_view label() const final { return "exception"; }
0050 
0051     // Write output to the given JSON object
0052     void output(JsonPimpl*) const final;
0053 
0054   private:
0055     std::unique_ptr<JsonPimpl> output_;
0056 };
0057 
0058 //---------------------------------------------------------------------------//
0059 }  // namespace celeritas