exception -----> Functions
/* current_exception */
exception_ptr current_exception() noexcept;
返回指向当前异常(或其副本)的智能指针【具体返回对象本身还是副本,是由具体实现库决定的】,如果当前没有异常发生,那么返回一个null-pointer。exception_ptr是一种shared smart pointer类型:只要仍然有一个exception_ptr指向它,那么被指向的exception对象必须保持有效状态,因此,可以利用exception_ptr跨线程间处理异常。
current_exception函数不抛出异常,但是如果实现该函数时,返回的是指向当前副本的指针,那么如果分配内存失败或者复制副本过程失败,将返回一个bad_exception或者一些未定义的值。
/* get_terminate */
terminate_handler get_terminate() noexcept;
返回终止处理函数。当没有catch语句块可以匹配时,自动调用该函数终止程序的执行。如果之前系统中没有通过set_terminate函数设置终止处理函数,那么根据不同实现系统可能返回一个abort()或者null-pointer。
/* get_unexpected */
unexpected_handler get_unexpected() noexcept;
当函数抛出throw列表中未声明的异常类型时,系统自动调用unexpected处理函数。如果未指定,那么该函数将返回一个unspecified value。
/* make_exception_ptr */
template <class E>
exception_ptr make_exception_ptr(E e) noexcept;
返回一个指向e的副本的exception_ptr对象。其行为等价于如下:
template <class E> exception_ptr make_exception_ptr (E e) noexcept {
try {
throw e;
} catch(...) {
return current_exception();
}
}
// make_exception_ptr example
#include <iostream> // std::cout
#include <exception> // std::make_exception_ptr, std::rethrow_exception
#include <stdexcept> // std::logic_error int main()
{
auto p = std::make_exception_ptr(std::logic_error("logic_error")); try
{
std::rethrow_exception (p);
}
catch(const std::exception& e)
{
std::cout << "exception caught: " << e.what() << '\n';
} return ;
}
/* rethrow_exception */
[[noreturn]] void rethrow_exception(exception_ptr p);
抛出p所指的异常对象。此时参数p不能为null exception_ptr,否则将引起未定义的行为。
/* set_terminate */
terminate_handler set_terminate(terminate_handler f) noexcept;
将f设置为终止处理函数。如果没有调用该函数设置f,那么系统在适当时候会调用abort()。程序中可以通过调用terminate()来显式调用当前的终止处理函数,即显式调用f或者abort()。
该函数不抛出异常,如果f是无效的或者没有被正确的实现,那么将引起未定义的行为。
// set_terminate example
#include <iostream> // std::cerr
#include <exception> // std::set_terminate
#include <cstdlib> // std::abort void myterminate()
{
std::cerr << "terminate handler called\n";
abort(); // forces abnormal termination
} int main()
{
std::set_terminate(myterminate);
throw ; // unhandled exception: calls terminate handler return ;
}

/* set_unexpected */
unexpected_handler set_unexpected(unexpected_handler f) noexcept;
/* terminate */
[[noreturn]]void terminate() noexcept;
调用当前终止处理函数。默认情况下调用abort(),但是也可以通过set_terminate()函数来指定。
// terminate example
#include <iostream> // std::cout, std::cerr
#include <exception> // std::exception, std::terminate int main()
{
char* p, *p2;
std::cout << "Attempting to allocate 2 GB at the same point ...";
try
{
p = new char[1024*1024*1024];
12 p2 = new char[1024*1024*1024];
}
catch (std::exception& e)
{
std::cerr << "ERROR: could not allocate storage\n";
std::terminate();
}
std::cout << "Ok\n"; delete[] p2;
delete[] p;
return ;
}

/* uncaught_exception */
bool uncaught_exception() noexcept;
如果已经抛出了异常,但是还没有被合适的catch语句块处理,则返回true,否则返回false。
/* unexpected */
[[noreturn]] void unexpected();
调用当前unexpected处理函数。默认情况下调用terminate()。但是可以通过set_unexpected()来指定。
/* throw_with_nested */
[[noreturn]] template <class T>
void throw_with_nested(T&& e);
抛出一个联合了当前异常及指定e的嵌套异常。当前异常变为nested exception,而指定e变为outer exception。
exception -----> Functions的更多相关文章
- Add GUI to connect to SQL
(*********************************************************************************) (* *) (* Below i ...
- [Python Essential Reference, Fourth Edition (2009)]读书笔记
Python programs are executed by an interpreter. When you use Python interactively, the special varia ...
- python3.4 build in functions from 官方文档 翻译中
2. Built-in Functions https://docs.python.org/3.4/library/functions.html?highlight=file The Python i ...
- 5.24 Declaring Attributes of Functions【转】
转自:https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html 5.24 Declaring Attributes o ...
- Functions
Small The first rule of functions is that they should be small.The second rule of functions is that ...
- Error Handling and Exception
The default error handling in PHP is very simple.An error message with filename, line number and a m ...
- Think Python - Chapter 16 - Classes and functions
16.1 TimeAs another example of a user-defined type, we’ll define a class called Time that records th ...
- Think Python - Chapter 03 - Functions
3.1 Function callsIn the context of programming, a function is a named sequence of statements that p ...
- exception -----> Typedefs & Classes
#include <exception> Typedefs exception_ptr 一种类型,描述了一个指向异常的指针 terminate_handler 一种类型,描述了一个适合作为 ...
随机推荐
- java中byte转换int时为何与0xff进行与运算
在剖析该问题前请看如下代码 public static String bytes2HexString(byte[] b) { String ret = ""; for (int ...
- JS判断对象是否存在的方法
Javascript语言的设计不够严谨,很多地方一不小心就会出错. 举例来说,请考虑以下情况. 现在,我们要判断一个全局对象myObj是否存在,如果不存在,就对它进行声明.用自然语言描述的算法如下: ...
- WIN32 DLL中使用MFC
最近用WIN32 DLL,为了方便要用到MFC的一些库,又不想转工程,就网上找了很多方法,发现没有详细的介绍,有的也行不通,现在成功在WIN32 DLL中使用了MFC,记录一下以防以后用到忘记 一.修 ...
- @service中构造方法报错
因为类首先被Spring实例化的时候,会调用构造函数.只有实例化后,才会注入.你等于没注入就调用了,所以报错.
- 生成ssl证书
http://blog.csdn.net/liuchunming033/article/details/48470575 https://segmentfault.com/a/119000000256 ...
- VBS创建数据库
'创建数据库'参数:strDBPath 字符串型 数据库文件的完整路径Sub CreateDataBase(strDBPath)Dim catObjSet catObj = CreateObject( ...
- 【缓存】利用Cache防止同一帐号重复登录
需求概要 对于B/S应用系统中客户经常会提出同一帐号不能重复登录的需求,就是说,用某一帐号登录系统后,在系统不超时的情况下,任何人都不能再用目前已登录的帐号登录系统.包括我目前的项目中同样有这一需求. ...
- 索引 使用use index优化sql查询
好博客:MySQL http://webnoties.blog.163.com/blog/#m=0&t=1&c=fks_08407108108708107008508508609508 ...
- CentOS6.5安装readline时报错:/usr/bin/ld : cannot find -lncurses
CentOS6.5安装readline时报错:/usr/bin/ld : cannot find -lncurses 解决方法: 安装ncurses-devel,输入命令: #yum install ...
- 关于javascript 里面类型的判断
javacript至今共有7中类型 Six data types that are primitives: Boolean Null Undefined Number String Symbol (n ...