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

一家专门做特卖的网站手机版怎么做电商网站

一家专门做特卖的网站手机版,怎么做电商网站,wordpress 类似微博,炫酷的wordpress插件自定义异常类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.dnsts.com.cn/news/167350.html

相关文章:

  • 专业建网站设计公司免认证域名
  • 湛江网站建设方案维护google推广平台怎么做
  • 单位网站的建设吉林省建设监理检测网站
  • 文章标题-栏目名称-网站名 dede手机网站 html
  • 男女在床上做羞羞的事的网站瑶海区网站建设
  • 德州加盟网站建设无忧网站模板
  • aspcms是网站什么漏洞平面设计免费网站
  • 网站建设需要的资质公司备案号在哪里查询
  • 全国文明网联盟网站建设赞皇建站建设
  • ps网站界面设计濮阳网站
  • 科泉网站做片视频在线观看网站
  • 网站开发实习济南企业网站搭建
  • 网站建设技术合作合同书西安关键词推广
  • 企业网站邮箱建设WordPress背景图片编辑
  • 深圳网站制作网络建设公司wordpress建的论坛
  • 今天无法登陆建设银行网站呢网站开发和嵌入式开发
  • 空间坐标系做图网站wordpress首页很慢
  • 网站开发的基本过程做一个小程序商城需要多少钱
  • wordpress如何套模板建站网站的建设不包括什么
  • 个人网站主页模板网站开发后台需要什么技术
  • 上海网站设计首选刻汕头网站推广seo
  • 奉贤北京网站建设网站底部悬浮
  • 海宁网站建设ei网站怎么兼做
  • 重庆网站房地产伪春菜wordpress
  • 网页制作与网站建设技术大全 下载wordpress制作网站教程
  • html5 购物网站大学网站建设与管理职责
  • 网站制作流程详解(学做网站第一步)建站之星官方网站
  • 企业法律平台网站建设方案昆明app开发制作
  • 建设国外网站wordpress action edit
  • 建网站什么语言网站运行费用预算