-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexceptions.org
More file actions
79 lines (57 loc) · 1.87 KB
/
Copy pathexceptions.org
File metadata and controls
79 lines (57 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#+title: Exceptions
#+author: Nelson Rodrigues
C++ 17 exception and no-exception
*Text and Source code:*
https://msdn.microsoft.com/en-us/library/4tebey8h.aspx
"... When the catch statement is reached, all of the automatic variables that are in scope
between the throw and catch statements are destroyed in a process that is known as stack unwinding ..."
*Text and Source code:*
https://docs.microsoft.com/en-us/cpp/cpp/exceptions-and-stack-unwinding-in-cpp?view=vs-2017
"... Prior to C++17 there were two kinds of exception specification. The noexcept specification
was new in C++11. It specifies whether the set of potential exceptions that can escape the function
is empty. The dynamic exception specification, or throw(optional_type_list) specification, was deprecated
in C++11 and removed in C++17, except for throw(), which is an alias for noexcept(true).
This exception specification was designed to provide summary information about what exceptions can be thrown
out of a function, but in practice it was found to be problematic ..."
*Text and Source code:*
https://docs.microsoft.com/en-us/cpp/cpp/exception-specifications-throw-cpp?view=vs-2017
*noexcept*
-It turns an exception throw into a call to std::terminate().
-One can make a compile-time query if the function has been declared as noexcept.
*Text and Source code:*
https://akrzemi1.wordpress.com/2014/04/24/noexcept-what-for/
#+BEGIN_EXAMPLE C++
#include <iostream>
#include <functional>
using namespace std;
void test(int i) noexcept
{
if(i == 0)
throw 2.0;
else
cout << "i = " << i << endl;
}
int main()
{
int * x = nullptr;
try
{
test(10);
test(0);
x = new int();
throw 20;
}
catch ( double e )
{
delete x;
cout << "An exception (double) = " << e << endl;
}
catch ( int e )
{
delete x;
cout << "An exception (int) = " << e << endl;
}
cout << "end";
return 0;
}
#+END_EXAMPLE