当前位置: 首页 > news >正文

一家专门做特卖的网站手机版美容加盟的网站建设

一家专门做特卖的网站手机版,美容加盟的网站建设,自己怎么做网站卖车,外贸公司网站开发自定义异常类spdlog_ex 标准库异常类#xff08;std::exception#xff09;系列#xff0c;能满足大多数使用异常的场景#xff0c;但对系统调用异常及错误信息缺乏支持。spdlog通过继承std::exception#xff0c;扩展对系统调用的支持#xff0c;实现自定义异常类spdlo…自定义异常类spdlog_ex 标准库异常类std::exception系列能满足大多数使用异常的场景但对系统调用异常及错误信息缺乏支持。spdlog通过继承std::exception扩展对系统调用的支持实现自定义异常类spdlog_ex。 spdlog_ex类声明只是在std::exception基础上添加了string类型的msg_成员提供支持errno的构造函数。 // include/spdlog/common.h class SPDLOG_API spdlog_ex : public std::exception { public:explicit spdlog_ex(std::string msg);spdlog_ex(const std::string msg, int last_errno);const char *what() const SPDLOG_NOEXCEPT override;private:std::string msg_; };异常 SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg): msg_(std::move(msg)) {}SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string msg, int last_errno) { #ifdef SPDLOG_USE_STD_FORMATmsg_ std::system_error(std::error_code(last_errno, std::generic_category()), msg).what(); #elsememory_buf_t outbuf;fmt::format_system_error(outbuf, last_errno, msg.c_str());msg_ fmt::to_string(outbuf); #endif对于通用的异常spdlog_ex只是将用户传入的异常提示信息存放到msg_。 spdlog_ex对errno的支持主要是将errno转换为对应错误文本信息存放到msg_字符串中。spdlog使用的是ftm库提供的format_system_error来完成转换工作。 what()函数 SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT {return msg_.c_str(); }what()是基类std::exception定义的virtual函数用户通常通过该接口获取异常信息。spdlog_ex返回存放异常信息的msg_。 异常的使用 spdlog提供了重载函数形式的接口throw_spdlog_ex。 SPDLOG_INLINE void throw_spdlog_ex(const std::string msg, int last_errno) {SPDLOG_THROW(spdlog_ex(msg, last_errno)); }SPDLOG_INLINE void throw_spdlog_ex(std::string msg) { SPDLOG_THROW(spdlog_ex(std::move(msg))); }抛出异常可以是这样 // send flush request to the thread pool SPDLOG_INLINE void spdlog::async_logger::flush_(){SPDLOG_TRY{auto pool_ptr thread_pool_.lock();if (!pool_ptr) {throw_spdlog_ex(async flush: thread pool doesnt exist anymore);}std::futurevoid future pool_ptr-post_flush(shared_from_this(), overflow_policy_);future.get();}SPDLOG_LOGGER_CATCH(source_loc()) }throw_spdlog_ex本质上也是throw spdlog_ex(…)这里多了宏定义SPDLOG_THROW。 #ifdef SPDLOG_NO_EXCEPTIONS#define SPDLOG_TRY#define SPDLOG_THROW(ex) \do { \printf(spdlog fatal error: %s\n, ex.what()); \std::abort(); \} while (0)#define SPDLOG_CATCH_STD #else#define SPDLOG_TRY try#define SPDLOG_THROW(ex) throw(ex)#define SPDLOG_CATCH_STD \catch (const std::exception ) { \} #endif实际上是提供了两种模式。抛出异常不抛出异常。 当没有定义宏SPDLOG_NO_EXCEPTIONS时正常抛出异常对象当定义了宏SPDLOG_NO_EXCEPTIONS时抛出异常替换为直接终止程序abort 因此在spdlog中捕获异常的代码块try-catch看起来会是这样 SPDLOG_INLINE thread_pool::~thread_pool() {// 析构函数不要抛出异常, 但释放线程池资源资源可能发生异常, 因此内部捕获并处理SPDLOG_TRY{for (size_t i 0; i threads_.size(); i) {// 有几个子线程就要post几个terminate的async_msg。post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block);}for (auto t : threads_) {t.join();}}SPDLOG_CATCH_STD }可以使用自定义捕获catch代码块替换SPDLOG_CATCH_STD。 SPDLOG_INLINE void spdlog::async_logger::backend_flush_() {for (auto sink : sinks_){SPDLOG_TRY{sink-flush();}SPDLOG_LOGGER_CATCH(source_loc())} } #ifndef SPDLOG_NO_EXCEPTIONS#define SPDLOG_LOGGER_CATCH(location) \catch (const std::exception ex) { \if (location.filename) { \err_handler_(fmt_lib::format(SPDLOG_FMT_STRING({} [{}({})]), ex.what(), \location.filename, location.line)); \} else { \err_handler_(ex.what()); \} \} \catch (...) { \err_handler_(Rethrowing unknown exception in logger); \throw; \} #else#define SPDLOG_LOGGER_CATCH(location) #endifcatch (const std::exception ex)捕获所有从 std::exception 派生的异常。 if (location.filename)如果提供了源代码位置信息文件名则格式化错误消息包括异常的 what() 信息和源代码位置。 err_handler_这是一个错误处理函数或对象用于处理和记录错误消息。 catch (…)捕获所有其他类型的异常。 err_handler_(“Rethrowing unknown exception in logger”)记录一个未知异常的错误消息。 throw重新抛出捕获的异常。 如果禁用了异常处理通过定义 SPDLOG_NO_EXCEPTIONS这个宏展开为空。
http://www.hkea.cn/news/14533238/

相关文章:

  • 住房城乡建设部网站诚信邢台搜
  • 网站设计公司佛山网站已付款方式
  • 广州网站快速优化排名怎么自建设部网站查询公司资质
  • 来个网站2021能用的男男互做网站
  • 下载软件的app郑州粒米seo顾问
  • 武功网站开发如何做打码网站
  • 上海平台网站建设公司一个网站怎样做两个后台
  • 杭州网站建设价格南宁公司网址怎么做
  • 怎么查看网站是否被百度惩罚降权或者被k做网站那些好
  • 网站设计思路招工做的网站
  • 网上做兼职的网站有哪些申京效率值联盟第一
  • h5在线网站建设网站页面框架设计
  • 广州 网站建设 行价拓客软件哪个好用
  • 彭州建设网站爱链接外链购买
  • 网站如何建设数据库企业网站建设维护方案
  • 科技馆网站建设背景哪些网站可以做宣传
  • 电子商务网站建设影响因素网站建站公司
  • 衡水网站seo绍兴网站建设方案报价
  • 各种网站app手机网站建设哪家公司好
  • wordpress外贸建站主题杂志 wordpress
  • 响应式环保网站网盟推广和搜索推广的区别
  • 网站制作 培训网页设计与网站开发素材
  • 网站的制作方法索尼电视网页浏览器
  • 宝塔网站建设iis建多个网站
  • 昊诺网站建设wordpress批量删除评论
  • 浙江网站seo360建筑网是什么公司
  • 四川星星建设集团有限公司网站昆山网站优化公司
  • 做网站优化常用工具企业站模板明细
  • 解聘 人力资源网站上怎么做微信销售平台
  • 重庆大渡口网站建设台州网站制作网站建设