/************************************************************************/
/*功能描述: boost exception使用实例 */
/*作者 : kernel_main */
/*创建时间: 2014.6.8 */
/************************************************************************/
#include <iostream>
#include <exception> #include <boost/exception/all.hpp> struct my_exception : /* 自定义异常类 */
virtual std::exception, /* 虚继承,struct默认public继承 */
virtual boost::exception /* 虚继承,struct默认public继承 */
{
/* 空实现,不需要实现代码 */
}; /* 异常信息的类型 */
typedef boost::error_info<struct tag_err_no, int> err_no;
typedef boost::error_info<struct tag_err_str,std::string> err_str; int main()
{
using namespace boost;
try
{
try
{
/* 抛出异常,存储错误码 */
throw my_exception() << err_no();
}
catch (my_exception& e) /* 捕获异常,使用引用形式 */
{
std::cout << *get_error_info<err_no>(e) << std::endl;
std::cout << e.what() << std::endl;
e << err_str("other info"); /* 向异常追加信息 */
throw; /* 再次抛出异常 */
}
}
catch (my_exception& e)
{
std::cout << *get_error_info<err_str>(e) << std::endl;
std::cout << e.what() << std::endl;
}
return ;
}

boost:exception使用实例的更多相关文章

  1. boost exception

    boost exception provides a new exception type, that lets you add data to an exception after it has b ...

  2. boost::asio 使用实例

    #include <iostream> #include <boost/asio.hpp> using namespace std; using namespace boost ...

  3. boost exception jam0.exe 异常错误

    在Windows 8 64 bit下执行boost_1_53_0的bootstrap.bat出现了jam0.exe执行错误 搜索网页发现需要修改两处文件: tools/build/v2/engine/ ...

  4. boost:thread使用实例

    /************************************************************************/ /*功能描述: boost thread使用实例 ...

  5. boost库之udp广播实例

    //UdpLinkServer.h //udp服务 #pragma once #include <boost/asio/ip/tcp.hpp> #include <boost/asi ...

  6. Boost 1.61.0 Library Documentation

    http://www.boost.org/doc/libs/1_61_0/ Boost 1.61.0 Library Documentation Accumulators Framework for ...

  7. boost开发指南

    C++确实很复杂,神一样的0x不知道能否使C++变得纯粹和干爽? boost很复杂,感觉某些地方有过度设计和太过于就事论事的嫌疑,对实际开发工作的考虑太过于理想化.学习boost本身就是一个复杂度,有 ...

  8. Win7下Boost库的安装

    Boost库是C++领域公认的经过千锤百炼的知名C++类库,涉及编程中的方方面面,简单记录一下使用时的安装过程 1.boost库的下载 boost库官网主页:www.boost.org 2.安装 将下 ...

  9. (八)boost库之异常处理

    (八)boost库之异常处理 当你面对上千万行的项目时,当看到系统输出了异常信息时,你是否想过,如果它能将文件名.行号等信息输出,该多好啊,曾经为此绞尽脑汁. 今天使用boost库,将轻松的解决这个问 ...

随机推荐

  1. Mac下finder中无法关闭的小条

    就是这个恶心的小东西,根本无法关闭.其实就是在finder中无意中输入了中文导致的(不是按Alt+F , 就是打开finder然后输入中文) 可以通过继续输入中文然后按esc退出.也可以用下面的设置尽 ...

  2. Apache Thrift学习之二(基础及原理)

    Apache Thrift 是 Facebook 实现的一种高效的.支持多种编程语言的远程服务调用的框架.本文将从 Java 开发人员角度详细介绍 Apache Thrift 的架构.开发和部署,并且 ...

  3. linux 查看占用端口并kill掉

    主要可以使用ps  命令 或 netstat 命令 weihong@data1:~/jd_parser/jd_parser$ ps aux | head USER PID %CPU %MEM VSZ ...

  4. ruby1.8到2.1语法改变

    1定义hash的语法改变old_way = {:foo => "bar", :one => 1}new_way = {foo: "bar", one ...

  5. $(document).ready() 与 window.onload的区别

    1.执行时间 window.onload 必须等到页面内所有元素(包括图片 css js等)加载完毕后才会执行. $(document).ready() 是DOM结构绘制完毕后就执行,不必等到所有元素 ...

  6. shell export

    export命令将使系统在创建每一个新的shell时定义这个变量的一个拷贝.这个过程称之为变量输出. 在脚本中export,跟在终端export原理一样. 他们都是一个子shell. http://b ...

  7. 编写一个go gRPC的服务

    前置条件: 获取 gRPC-go 源码 $ go get google.golang.org/grpc 简单例子的源码位置: $ cd $GOPATH/src/google.golang.org/gr ...

  8. [SQL]reName存储过程

    exec sp_helptext aa--应用sp_helptext查看存储过程的定义文本 exec sp_depends aa --通过sp_depends查看存储过程的相关性 exec sp_he ...

  9. PetaPoco.Core.ttinclude修改

    /// <summary> /// Adds the singular rule. /// </summary> /// <param name="rule&q ...

  10. php中引用符号(&)的使用详解

    php的引用就是在变量或者函数.对象等前面加上&符号,在PHP 中引用的意思是:不同的名字访问同一个变量内容,下面介绍如何使用PHP的引用 与C语言中的指针是有差别的.C语言中的指针里面存储的 ...