muduo 库解析之六:Exception

源码

Exception.h

#pragma once

#include <exception>
#include <string>

namespace muduo
{
    class Exception : public std::exception
    {
    public:
        explicit Exception(std::string msg);
        ~Exception() noexcept override = default;

        const char *what() const noexcept override
        {
            return msg_.c_str();
        }

        const char *stack() const noexcept
        {
            return stack_.c_str();
        }

    private:
        std::string msg_;
        std::string stack_;
    };
}

Exception.cc

#include "Exception.h"

#include "CurrentThread.h"

namespace muduo
{
    Exception::Exception(std::string msg) : msg_(std::move(msg)), stack_(CurrentThread::stack_trace(false))
    {
    }
}
原文地址:https://www.cnblogs.com/xiaojianliu/p/14696660.html