Code View

plugin / plugin-2.2.0.0 / src / dso / Exception.hh
// SPDX-License-Identifier: MIT
#pragma once

#include <exception>
#include <string>

#include <dso/DSOVisibility.hh>

namespace fedem
{
  namespace exception
  {
    /**
     * Exception is the base class for all exceptions in the library.
     */
    class PLUGIN_EXPORT Exception
      : public std::exception
    {
      public:
        Exception( ) noexcept;
        Exception( Exception const& ) noexcept;
        ~Exception( ) noexcept override;

        Exception& operator=( Exception const& ) noexcept;

        /**
         * Returns a formatted description of the exception.
         */
        virtual std::string const description( ) const noexcept;

        /**
         * Returns the exception message as a string (pure virtual).
         */
        virtual std::string whatStr( ) const noexcept = 0;

        /**
         * Returns the exception message as a C string.
         */
        char const* what( ) const noexcept override;

        /**
         * Returns the source filename where the exception was thrown.
         * If NDEBUG is defined, returns an empty string.
         */
        std::string filename( ) const noexcept;

        /**
         * Sets the source filename.
         */
        void filename( std::string const& fname ) noexcept;

        /**
         * Returns the line number where the exception was thrown.
         * If NDEBUG is defined, returns zero.
         */
        unsigned long lineNumber( ) const noexcept;

        /**
         * Sets the line number.
         */
        void lineNumber( unsigned long lineNo ) noexcept;

      private:
        std::string exceptionFilename;
        unsigned long exceptionLineNumber;
        mutable std::string exceptionDescription;
    };
  }  // namespace exception
}  // namespace fedem