Integrating Boost Exception in Existing Exception Class Hierarchies
diff --git a/doc/exception_ptr.html b/doc/exception_ptr.html
index d150f8f..dd216a6 100644
--- a/doc/exception_ptr.html
+++ b/doc/exception_ptr.html
@@ -36,6 +36,8 @@ boost
It is illegal for multiple threads to modify the same exception_ptr object concurrently.
While calling current_exception makes a copy of the current exception object, it is still possible for the two copies to share internal state. Therefore, in general it is not safe to call rethrow_exception concurrently to throw the same exception object into multiple threads.
+Nesting of exceptions
+An exception_ptr can be added as error_info to any boost::exception . This is a convenient way to nest exceptions. There is no limit on the depth of the nesting, however cyclic references result in undefined behavior.
See Also:
Boost Exception
diff --git a/doc/source/boost-exception.reno b/doc/source/boost-exception.reno
index 93b1f0d..828a09e 100644
--- a/doc/source/boost-exception.reno
+++ b/doc/source/boost-exception.reno
@@ -48,6 +48,748 @@
reno_context
+
+
+
+
+
+ 1
+ BEFF039468E0E9A3719E5CB51DA9710812D146B587BAF573D1670908BB97C0CA
+ 35548578
+ 1983
+ 91
+
+
+
+
+
+ 0
+ ../../../../boost/throw_exception.hpp
+ 0
+ 0
+
+
+
+
+ boost/throw_exception.hpp
+
+
+
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 6
+
+ reno_context
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+
+ boost/exception/enable_current_exception.hpp
+
+
+
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 7
+
+ reno_context
+
+
+
+
+
+
+ 2
+ 9A4ECF9A49A73AED83C1565CB8C67AE1519E8AFE6818F968B4C4733CB9E86CEF
+ 1615599655
+ 68
+ 227
+ 34F0583BC8DE767CE2D79721E1F956895E43E5397473B1050F59BE7E26C773DB
+ 805836816
+ 66
+ 1
+
+
+
+
+
+ 0
+ ../../../../boost/exception/error_info.hpp
+ 0
+ 0
+
+
+
+
+ boost/exception/error_info.hpp
+
+
+
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 8
+
+ reno_context
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+
+ exception types as simple semantic tags
+
+
+
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 9
+
+ reno_context
+
+
+
+
+
+
+ 1
+ CAD6C404CB725D336A44920D2341ECA131149AB02C368B59028F8147F16737BF
+ 2258638601
+ 94
+ 227
+
+
+
+
+
+ 0
+ ../../../../boost/exception/info_tuple.hpp
+ 0
+ 0
+
+
+
+
+ boost/exception/info_tuple.hpp
+
+
+
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 10
+
+ reno_context
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+
+ Macros
+
+
+ macros
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 11
+
+ reno_context
+
+
+
+
+
+
+ 1
+ 641BB230CEBF638811480BE0E3A96ABCB7CC9CC7E1C1A9C51FBAB296FFB6B7B1
+ 4248389286
+ 4113
+ 323
+
+
+
+
+
+ 0
+ ../../../../boost/exception/info.hpp
+ 0
+ 0
+
+
+
+
+ boost/exception/info.hpp
+
+
+
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 12
+
+ reno_context
+
+
+
+
+
+
+ 1
+ 21E8093D2AF6946EAE135823066EF38B9DC8870432B44C81E585FF63A72F9903
+ 3352783584
+ 12170
+ 323
+
+
+
+
+
+ 0
+ ../../../../boost/exception_ptr.hpp
+ 0
+ 0
+
+
+
+
+ boost/exception_ptr.hpp
+
+
+
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 13
+
+ reno_context
+
+
+
+
+
+
+ 1
+ A14B5595A6DD87562792D402B48500AAD71FA1ABD75C14EDF089FCC7318CBB9B
+ 3469762901
+ 468
+ 227
+
+
+
+
+
+ 0
+ ../../../../boost/exception/current_exception_cast.hpp
+ 0
+ 0
+
+
+
+
+ boost/exception/current_exception_cast.hpp
+
+
+
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 14
+
+ reno_context
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+
+ page index
+
+
+ page_idx
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 15
+
+ reno_context
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+
+ Motivation
+
+
+ motivation
+
+
+
+
+
+ 7
+ 2
+ (:include include:)
(:auto also explicit="
+ 1
+
+ 0
+
+ -8
+
+
+ 2
+
+ 1
+
+ 0
+
+ 16
+
+ reno_context
+
+
+
+
+
+
+ 1
+ D9B8E6AA12A4F33953B1A961FA590C5A3840234B6531CA8C04AC985AD5800835
+ 2432554768
+ 702
+ 408
+
+
+
+
+
+ 0
+ ../../example/enable_error_info.cpp
+ 0
+ 0
+
+
+
+
+ integrating boost exception in existing exception class hierarchies
+
+
+ tutorial_enable_error_info
+
+
+
+
+ 2
+
+ 1
+
+ 0
+
+ 17
+
+ reno_context
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+
+ frequently asked questions
+
+
+
+
+
+
+
+ 2
+ ":)
+
+
+
+
+ 0
+
+ -16
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ -17
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 18
+
+ reno_context
+
+
+
+
+
+
+ 2
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
+ 1516D0B7E11CBEB60CE4222565ACCAFF2E9857A8A505C1C26E2AE90087250581
+ 3624753243
+ 279
+ 26
+
+
+
+
+
+ 0
+ ../../../../boost/exception_ptr.hpp
+ 0
+ 0
+
+
+
+
+ original_exception_type
+
+
+
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 19
+
+ reno_context
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+
+ Headers
+
+
+ headers
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 20
+
+ reno_context
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+
+ Types
+
+
+ types
+
+
+
+
+
+ 1
+ 2
+ (:include include:)
(:auto also:)
+
+
+
+
+ 0
+
+ 21
+
+ reno_context
+
+
+
+
+
+
+ 1
+ 4ED9709788BBAB4DE7CF336561606B8C0B41F70877A3395F4EE026F4AEB66CC6
+ 743998427
+ 409
+ 307
+
+
+
+
+
+ 0
+ ../../example/cloning_1.cpp
+ 0
+ 0
+
+
+
+
+ using enable_current_exception at the time of the throw
+
+
+ using_enable_cloning
+
+
+
+
+
+ 0
+
+
+
+
+ 0
+
+ 22
+
+ reno_context
+
@@ -89,7 +831,7 @@
0
- 6
+ 23
reno_context
@@ -142,7 +884,7 @@
0
- 7
+ 24
reno_context
@@ -180,7 +922,7 @@
0
- 8
+ 25
reno_context
@@ -219,735 +961,6 @@
0
-
-
- 0
-
- 9
-
- reno_context
-
-
-
-
-
-
- 1
- BEFF039468E0E9A3719E5CB51DA9710812D146B587BAF573D1670908BB97C0CA
- 35548578
- 1983
- 91
-
-
-
-
-
- 0
- ../../../../boost/throw_exception.hpp
- 0
- 0
-
-
-
-
- boost/throw_exception.hpp
-
-
-
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 10
-
- reno_context
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
-
- boost/exception/enable_current_exception.hpp
-
-
-
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 11
-
- reno_context
-
-
-
-
-
-
- 2
- 9A4ECF9A49A73AED83C1565CB8C67AE1519E8AFE6818F968B4C4733CB9E86CEF
- 1615599655
- 68
- 227
- 34F0583BC8DE767CE2D79721E1F956895E43E5397473B1050F59BE7E26C773DB
- 805836816
- 66
- 1
-
-
-
-
-
- 0
- ../../../../boost/exception/error_info.hpp
- 0
- 0
-
-
-
-
- boost/exception/error_info.hpp
-
-
-
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 12
-
- reno_context
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
-
- exception types as simple semantic tags
-
-
-
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 13
-
- reno_context
-
-
-
-
-
-
- 1
- CAD6C404CB725D336A44920D2341ECA131149AB02C368B59028F8147F16737BF
- 2258638601
- 94
- 227
-
-
-
-
-
- 0
- ../../../../boost/exception/info_tuple.hpp
- 0
- 0
-
-
-
-
- boost/exception/info_tuple.hpp
-
-
-
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 14
-
- reno_context
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
-
- Macros
-
-
- macros
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 15
-
- reno_context
-
-
-
-
-
-
- 1
- A449DE2B3A2CDAE9DD932C06D224B3E07C95EBACBB4EA5890CA4CCF2DC74A693
- 1718307056
- 4118
- 323
-
-
-
-
-
- 0
- ../../../../boost/exception/info.hpp
- 0
- 0
-
-
-
-
- boost/exception/info.hpp
-
-
-
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 16
-
- reno_context
-
-
-
-
-
-
- 1
- ACBC114551B7A04441A0452AB97D25519D6D2AE97DA6C5DDBC2E7C4B9002F847
- 4238517159
- 11368
- 323
-
-
-
-
-
- 0
- ../../../../boost/exception_ptr.hpp
- 0
- 0
-
-
-
-
- boost/exception_ptr.hpp
-
-
-
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 17
-
- reno_context
-
-
-
-
-
-
- 1
- A14B5595A6DD87562792D402B48500AAD71FA1ABD75C14EDF089FCC7318CBB9B
- 3469762901
- 468
- 227
-
-
-
-
-
- 0
- ../../../../boost/exception/current_exception_cast.hpp
- 0
- 0
-
-
-
-
- boost/exception/current_exception_cast.hpp
-
-
-
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 18
-
- reno_context
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
-
- page index
-
-
- page_idx
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 19
-
- reno_context
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
-
- Motivation
-
-
- motivation
-
-
-
-
-
- 7
- 2
- (:include include:)
(:auto also explicit="
- 1
-
- 0
-
- -12
-
-
- 2
-
- 1
-
- 0
-
- 20
-
- reno_context
-
-
-
-
-
-
- 1
- D9B8E6AA12A4F33953B1A961FA590C5A3840234B6531CA8C04AC985AD5800835
- 2432554768
- 702
- 408
-
-
-
-
-
- 0
- ../../example/enable_error_info.cpp
- 0
- 0
-
-
-
-
- integrating boost exception in existing exception class hierarchies
-
-
- tutorial_enable_error_info
-
-
-
-
- 2
-
- 1
-
- 0
-
- 21
-
- reno_context
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
-
- frequently asked questions
-
-
-
-
-
-
-
- 2
- ":)
-
-
-
-
- 0
-
- 22
-
- reno_context
-
-
-
-
-
-
- 2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
- 1516D0B7E11CBEB60CE4222565ACCAFF2E9857A8A505C1C26E2AE90087250581
- 3624753243
- 279
- 26
-
-
-
-
-
- 0
- ../../../../boost/exception_ptr.hpp
- 0
- 0
-
-
-
-
- original_exception_type
-
-
-
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 23
-
- reno_context
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
-
- Headers
-
-
- headers
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- -20
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 24
-
- reno_context
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
-
- Types
-
-
- types
-
-
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
-
-
- 0
-
- 25
-
- reno_context
-
-
-
-
-
-
- 1
- 4ED9709788BBAB4DE7CF336561606B8C0B41F70877A3395F4EE026F4AEB66CC6
- 743998427
- 409
- 307
-
-
-
-
-
- 0
- ../../example/cloning_1.cpp
- 0
- 0
-
-
-
-
- using enable_current_exception at the time of the throw
-
-
- using_enable_cloning
-
-
-
-
-
- 0
-
-
0
@@ -1054,14 +1067,14 @@
2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
6B3B617AC518A2177BDB89656E726B4E4D79577E289130493A61BAE24FB64838
3173127726
1101
- 1777
+ 2184
@@ -1148,13 +1161,13 @@
2
- 7BD35FAECA8BDD2E78E08EB02CF7F36163AE21D6859C73267AC53A05E5797909
- 2464409114
- 3681
- 502
- DBE4A27FCB9297C314B3F52A460B55A5540B2A3F173D48C8CD042388D19253E2
- 263970566
- 3656
+ 02F77B8305279514F37A75FA6454AE750E04E7AA7934D395EFB52BCC7642965E
+ 430535365
+ 3379
+ 560
+ D08B74734CDA5115D9E47783E2994C2836BE241FB25E589BB4C67F2596727C03
+ 24341149
+ 3347
26
@@ -1295,13 +1308,13 @@
2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
- F86EB07D04CD0D0645080D1121DA899746D0C45137E17E1D9BE605E75396F047
- 1983537541
- 1346
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
+ AF894656AC8CED6190EEEE08B051DBF2106A393E313BB5BB1C17D4808EFED761
+ 1496105832
+ 1753
429
@@ -1344,14 +1357,14 @@
2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
E23085202D084CBB50F289988A6A592F06D923B77D0AB25D7A98A7188DF5BE3B
1414247481
766
- 9687
+ 10094
@@ -1583,14 +1596,14 @@
2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
- 0E9DF8366080712A816BE91ABCEF1E2044145B63D75B0B995B537900F378189E
- 1069696031
- 255
- 10762
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
+ B20A3D4631F3B2415EED1888B65FA33D7AED20F86BE196159D9297AAED115787
+ 3293519666
+ 117
+ 11169
@@ -1713,9 +1726,9 @@
2
- 1D3204D3ADDAB7AA716BEA1489EA852A9D6B5C110243364F6931FEF1CC2E5F88
- 422052608
- 3923
+ AED5E79246B32BDF0E5C6CD8BDDC3370FD0BA1EFE3D4CE76C4A6D36A123F2E20
+ 228982966
+ 3918
518
6E325144EF4F41FA3A225EB30729101382C4E99B3D6160E307311E4B4E641010
1097215175
@@ -2111,14 +2124,14 @@
2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
0066D4E6E6B189906E6DE04F08509F3737511701A1B1355B37511EC18E8371F4
2078296250
305
- 10455
+ 10862
@@ -2331,19 +2344,6 @@
(:include include:)
(:auto also:)
-
-
- 0
-
- -21
-
-
-
- 1
- 2
- (:include include:)
(:auto also:)
-
-
0
@@ -2358,14 +2358,14 @@
2
- 1D3204D3ADDAB7AA716BEA1489EA852A9D6B5C110243364F6931FEF1CC2E5F88
- 422052608
- 3923
+ AED5E79246B32BDF0E5C6CD8BDDC3370FD0BA1EFE3D4CE76C4A6D36A123F2E20
+ 228982966
+ 3918
518
D31BCE814DF5B8B718E7EB67A194AD08EF716A26D422E436596ABA1F145007D8
4055211476
525
- 3392
+ 3387
@@ -2456,9 +2456,9 @@
1
- B26AA4D68CD040C376C32D7D469C926EC02DB8F76A3DA3275D14CCABCA02902C
- 1262147856
- 4435
+ 95AD55ACCB1C17C1DBA4C309BDFCBD4B66E52CD9A2F54FDAD2D642A00342D001
+ 3194412598
+ 4599
323
@@ -2591,11 +2591,15 @@
- 1
- 683D57B85DAEB8F69927D079F2038E0C64853D2B8A8CB5273B76ACAD5901DDFD
- 878883983
- 573
- 4185
+ 2
+ D57BF77EE44CD2755E24A56DDC3E159716D04A7ABE009AE977D4926EFEC00F73
+ 2498368808
+ 973
+ 3941
+ 9432C669E21C649A86AC6DC5A34275B483A7D2D38118A462DF1C1CD7BBE5ED51
+ 2535426829
+ 441
+ 110
@@ -2802,6 +2806,28 @@
0
+
+
+ 0
+
+ -20
+
+
+
+ 0
+
+
+
+
+ 0
+
+ -21
+
+
+
+ 0
+
+
0
@@ -2824,17 +2850,6 @@
0
-
-
- 0
-
- -20
-
-
-
- 0
-
-
0
@@ -3196,7 +3211,7 @@
0
- -6
+ -23
2
@@ -3254,17 +3269,6 @@
0
-
-
- 0
-
- -21
-
-
-
- 0
-
-
0
@@ -3352,126 +3356,6 @@
-5
-
- 15
- 2
- [@#include <(:link
- 1
-
- 0
-
- -58
-
-
- 2
- :)>
#include <(:link
- 1
-
- 0
-
- -11
-
-
- 2
- :)>
#include <(:link
- 1
-
- 0
-
- -49
-
-
- 2
- :)>
#include <(:link
- 1
-
- 0
-
- -53
-
-
- 2
- :)>
#include <(:link
- 1
-
- 0
-
- -15
-
-
- 2
- :)>
#include <(:link
- 1
-
- 0
-
- -13
-
-
- 2
- :)>
#include <(:link
- 1
-
- 0
-
- -16
-
-
- 2
- :)>@]
-
-
-
-
- 0
-
- -6
-
-
-
- 0
-
-
-
-
- 0
-
- -7
-
-
-
- 3
- 2
- [@(:include
- 1
-
- 0
-
- -26
-
-
- 2
- decl:)@]
-
-
-
-
- 0
-
- -8
-
-
-
- 0
-
-
-
-
- 0
-
- -9
-
-
5
2
@@ -3500,7 +3384,7 @@
0
- -10
+ -6
@@ -3522,7 +3406,7 @@
0
- -11
+ -7
@@ -3544,7 +3428,7 @@
0
- -12
+ -8
@@ -3555,7 +3439,7 @@
0
- -13
+ -9
@@ -3577,7 +3461,7 @@
0
- -14
+ -10
@@ -3588,7 +3472,7 @@
0
- -15
+ -11
@@ -3619,7 +3503,7 @@
0
- -16
+ -12
@@ -3639,7 +3523,7 @@
0
- -22
+ -18
2
@@ -3686,7 +3570,7 @@
0
- -17
+ -13
@@ -3704,6 +3588,50 @@
decl:)@]
+
+
+ 0
+
+ -14
+
+
+
+ 0
+
+
+
+
+ 0
+
+ -15
+
+
+
+ 0
+
+
+
+
+ 0
+
+ -16
+
+
+
+ 0
+
+
+
+
+ 0
+
+ -17
+
+
+
+ 0
+
+
0
@@ -3730,13 +3658,100 @@
0
- -22
+ -20
0
+
+
+ 0
+
+ -21
+
+
+
+ 0
+
+
+
+
+ 0
+
+ -22
+
+
+
+ 15
+ 2
+ [@#include <(:link
+ 1
+
+ 0
+
+ -58
+
+
+ 2
+ :)>
#include <(:link
+ 1
+
+ 0
+
+ -7
+
+
+ 2
+ :)>
#include <(:link
+ 1
+
+ 0
+
+ -49
+
+
+ 2
+ :)>
#include <(:link
+ 1
+
+ 0
+
+ -53
+
+
+ 2
+ :)>
#include <(:link
+ 1
+
+ 0
+
+ -11
+
+
+ 2
+ :)>
#include <(:link
+ 1
+
+ 0
+
+ -9
+
+
+ 2
+ :)>
#include <(:link
+ 1
+
+ 0
+
+ -12
+
+
+ 2
+ :)>@]
+
+
0
@@ -3748,17 +3763,6 @@
0
-
-
- 0
-
- -20
-
-
-
- 0
-
-
0
@@ -3767,7 +3771,18 @@
- 0
+ 3
+ 2
+ [@(:include
+ 1
+
+ 0
+
+ -26
+
+
+ 2
+ decl:)@]
@@ -4169,17 +4184,6 @@
0
-
-
- 0
-
- -21
-
-
-
- 0
-
-
0
@@ -4299,18 +4303,7 @@
- 3
- 2
- [@typedef T (:link
- 1
-
- 0
-
- -6
-
-
- 2
- mod="m":);@]
+ 0
@@ -4442,7 +4435,27 @@
- 0
+ 5
+ 2
+ [@typedef (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<struct tag_original_exception_type,std::type_info const *>
+ 1
+
+ 0
+
+ -18
+
+
+ 2
+ ;@]
@@ -4456,6 +4469,28 @@
0
+
+
+ 0
+
+ -20
+
+
+
+ 0
+
+
+
+
+ 0
+
+ -21
+
+
+
+ 0
+
+
0
@@ -4464,27 +4499,7 @@
- 5
- 2
- [@typedef (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<struct tag_original_exception_type,std::type_info const *>
- 1
-
- 0
-
- -22
-
-
- 2
- ;@]
+ 0
@@ -4495,18 +4510,18 @@
- 0
-
-
-
-
- 0
-
- -20
-
-
-
- 0
+ 3
+ 2
+ [@typedef T (:link
+ 1
+
+ 0
+
+ -23
+
+
+ 2
+ mod="m":);@]
@@ -4949,7 +4964,7 @@
0
- -6
+ -23
2
@@ -5185,7 +5200,7 @@
0
- -6
+ -23
2
@@ -5201,17 +5216,6 @@
mod="m":)() const;@]
-
-
- 0
-
- -21
-
-
-
- 0
-
-
0
@@ -5258,7 +5262,7 @@
0
- -6
+ -23
2
@@ -5393,27 +5397,9 @@
- 5
+ 1
2
- (:auto !!!:)
(:include synopsis:)
!!!!Definition:
The expression
- 1
-
- 0
-
- -52
-
-
- 2
- <Tag,T>::(:link
- 1
-
- 0
-
- -6
-
-
- 2
- mod="m":) evaluates to T.
+ (:auto !!!:)
!!!Synopsis
(:include synopsis:)
@@ -5426,7 +5412,7 @@
1
2
- (:auto !!!:)
!!!Synopsis
(:include synopsis:)
+ (:auto !!:)
!!!Synopsis
(:include synopsis:)
@@ -5436,67 +5422,6 @@
-8
-
- 3
- 2
- !!!!Example:
this is a possible output from the (:link
- 1
-
- 0
-
- -30
-
-
- 2
- :) function, as used in ''libs/exception/example/example_io.cpp:''
[@example_io.cpp(83): Throw in function class boost::shared_ptr<struct _iobuf> __cdecl my_fopen(const char *,const char *)
Dynamic exception type: class boost::exception_detail::clone_impl<class fopen_error>
std::exception::what: example_io error
[struct tag_errno *] = 2, OS says "No such file or directory"
[struct tag_file_name *] = tmp1.txt
[struct tag_function *] = fopen
[struct tag_open_mode *] = rb@]
-
-
-
-
- 0
-
- -9
-
-
-
- 1
- 2
- (:auto !!:)
!!!Synopsis
(:include synopsis:)
-
-
-
-
- 0
-
- -10
-
-
-
- 1
- 2
- (:auto !!!:)
!!!Synopsis
(:include synopsis:)
-
-
-
-
- 0
-
- -11
-
-
-
- 1
- 2
- (:auto !!:)
!!!Synopsis
(:include synopsis:)
-
-
-
-
- 0
-
- -12
-
-
7
2
@@ -5530,6 +5455,58 @@
:) { };
struct io_error: virtual exception_base { };
struct file_error: virtual io_error { };
struct read_error: virtual io_error { };
struct file_read_error: virtual file_error, virtual read_error { };@]
Using this approach, exception types become a simple tagging system for categorizing errors and selecting failures in exception handlers.
+
+
+ 0
+
+ -9
+
+
+
+ 1
+ 2
+ (:auto !!:)
!!!Synopsis
(:include synopsis:)
+
+
+
+
+ 0
+
+ -10
+
+
+
+ 1
+ 2
+ (:auto !!:)
(:pagelist tags="macro":)
+
+
+
+
+ 0
+
+ -11
+
+
+
+ 1
+ 2
+ (:auto !!:)
!!!Synopsis
(:include synopsis:)
+
+
+
+
+ 0
+
+ -12
+
+
+
+ 1
+ 2
+ (:auto !!:)
!!!Synopsis
(:include synopsis:)
+
+
0
@@ -5550,58 +5527,6 @@
-14
-
- 1
- 2
- (:auto !!:)
(:pagelist tags="macro":)
-
-
-
-
- 0
-
- -15
-
-
-
- 1
- 2
- (:auto !!:)
!!!Synopsis
(:include synopsis:)
-
-
-
-
- 0
-
- -16
-
-
-
- 1
- 2
- (:auto !!:)
!!!Synopsis
(:include synopsis:)
-
-
-
-
- 0
-
- -17
-
-
-
- 1
- 2
- (:auto !!:)
!!!Synopsis
(:include synopsis:)
-
-
-
-
- 0
-
- -18
-
-
1
2
@@ -5612,7 +5537,7 @@
0
- -19
+ -15
@@ -5769,69 +5694,7 @@
0
- -22
-
-
-
- 9
- 2
- (:auto !!!:)
(:include synopsis:)
This
- 1
-
- 0
-
- -52
-
-
- 2
- typedef is used by
- 1
-
- 0
-
- -34
-
-
- 2
- if it defaults to returning an
- 1
-
- 0
-
- -33
-
-
- 2
- that refers to an object of type
- 1
-
- 0
-
- -28
-
-
- 2
- , to record in it the std::type_info of the original exception object.
-
-
-
-
- 0
-
- -23
-
-
-
- 1
- 2
- (:auto !!:)
(:pagelist fmt="index" tags="hpp" sort_prefix="6":)
-
-
-
-
- 0
-
- -20
+ -16
@@ -5869,7 +5732,7 @@
0
- -5
+ -22
2
@@ -5961,2430 +5824,7 @@
0
- -24
-
-
-
- 1
- 2
- (:auto !!:)
(:pagelist fmt="index" tags="type":)
-
-
-
-
- 0
-
- -25
-
-
-
- 11
- 2
- (:auto !!!:)
Here is how cloning can be enabled in a throw-expression (15.1):
[@#include <(:link
- 1
-
- 0
-
- -15
-
-
- 2
- :)>
#include <stdio.h>
#include <errno.h>
typedef boost::error_info<struct tag_errno,int> errno_info;
class file_read_error: public boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) { };
void
file_read( FILE * f, void * buffer, size_t size )
{
if( size!=fread(buffer,1,size,f) )
throw boost::(:link
- 1
-
- 0
-
- -37
-
-
- 2
- :)(file_read_error()) <<
errno_info(errno);
}@]
Of course, (:link
- 1
-
- 0
-
- -37
-
-
- 2
- :) may be used with any exception type; there is no requirement that it should derive from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :).
-
-
-
-
- 0
-
- -26
-
-
-
- 5
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
T must be a class with an accessible no-throw copy constructor as per (15.5.1).
!!!!Returns:
* If T derives from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :), the returned object is of type T and is a copy of x.
* Otherwise, the returned object is of an unspecified type that derives publicly from both T and boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :). The T sub-object is initialized from x by the T copy constructor.
!!!!Throws:
Nothing.
-
-
-
-
- 0
-
- -27
-
-
-
- 17
- 2
- (:auto !!!:)
The following example demonstrates how errno can be stored in exception objects using Boost Exception:
[@#include <(:link
- 1
-
- 0
-
- -5
-
-
- 2
- :)>
#include <errno.h>
#include <iostream>
typedef boost::(:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<struct tag_errno,int> errno_info; //(1)
class my_error: public boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :), public std::exception { }; //(2)
void
f()
{
throw my_error() << errno_info(errno); //(3)
}
@]
First, we instantiate the (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :) template using a unique identifier -- tag_errno, and the type of the info it identifies -- int. This provides compile-time type safety for the various values stored in exception objects.
Second, we define class my_error, which derives from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :).
Finally, (3) illustrates how the typedef from (1) can be used with (:link
- 1
-
- 0
-
- -56
-
-
- 2
- |operator<<:) to store values in exception objects at the point of the throw.
The stored errno value can be recovered at a later time like this:
[@// ...continued
void
g()
{
try
{
f();
}
catch(
my_error & x )
{
if( int const * err=boost::(:link
- 1
-
- 0
-
- -57
-
-
- 2
- :)<errno_info>(x) )
std::cerr << "Error code: " << *err;
}
}@]
The (:link
- 1
-
- 0
-
- -57
-
-
- 2
- :) function template is instantiated with the typedef from (1), and is passed an exception object of a polymorphic type. If the exception object contains the requested value, err will point to it; otherwise a null pointer is returned.
-
-
-
-
- 0
-
- -28
-
-
-
- 5
- 2
- (:auto !!!:)
(:include synopsis:)
This type is used by the (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) support in Boost Exception. Please see (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :).
-
-
-
-
- 0
-
- -29
-
-
-
- 19
- 2
- (:auto !!:)
Boost Exception provides a namespace-scope function (:link
- 1
-
- 0
-
- -30
-
-
- 2
- :) which takes a boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :). The returned string contains:
*the string representation of all data objects added to the boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) through (:link
- 1
-
- 0
-
- -56
-
-
- 2
- mod="/":);
*the output from std::exception::what;
*additional platform-specific diagnostic information.
The returned string is not presentable as a friendly user message, but because it is generated automatically, it is useful for debugging or logging purposes. Here is an example:
[@#include <(:link
- 1
-
- 0
-
- -5
-
-
- 2
- :)>
#include <iostream>
void f(); //throws unknown types that derive from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :).
void
g()
{
try
{
f();
}
catch(
boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) & e )
{
std::cerr << (:link
- 1
-
- 0
-
- -30
-
-
- 2
- :)(e);
}
}@]
(:include
- 1
-
- 0
-
- -8
-
-
- 2
- :)
-
-
-
-
- 0
-
- -30
-
-
-
- 29
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Returns:
A string value that contains varying amount of implementation-specific diagnostic information about the passed exception object:
*If E can be statically converted to boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :), the returned value contains the string representations of all (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :) objects stored in the boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) through (:link
- 1
-
- 0
-
- -56
-
-
- 2
- mod="/":), along with other diagnostic information relevant to the exception. If e can be dynamically converted to std::exception, the returned value also contains the what() string.
*Otherwise, if E can be statically converted std::exception:
**if e can be dynamically converted to boost::exception, the returned value is the same as if E could be statically converted to boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :);
**otherwise the returned value contains the what() string.
*Otherwise, the boost::
- 1
-
- 0
-
- -30
-
-
- 2
- template is not available.
The string representation of each (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :) object is deduced by a function call that is bound at the time the (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<Tag,T> template is instantiated. The following overload resolutions are attempted in order:
#Unqualified call to to_string(x), where x is of type (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<Tag,T> (the return value is expected to be of type std::string.)
#Unqualified call to to_string(x.(:link
- 1
-
- 0
-
- -55
-
-
- 2
- mod="m":)()) (the return value is expected to be of type std::string.)
#Unqualified call to s << x.(:link
- 1
-
- 0
-
- -55
-
-
- 2
- mod="m":)(), where s is a std::ostringstream.
The first successfully bound function is used at the time (:link
- 1
-
- 0
-
- -30
-
-
- 2
- :) is called; if all 3 overload resolutions are unsuccessful, the system is unable to convert the (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :) object to string, and ''an unspecified stub string value is used without issuing a compile error.''
!!!!Notes:
*The format of the returned string is unspecified.
*The returned string is ''not'' user-friendly.
*The returned string may include additional platform-specific diagnostic information.
(:include
- 1
-
- 0
-
- -8
-
-
- 2
- :)
-
-
-
-
- 0
-
- -31
-
-
-
- 19
- 2
- (:auto !!:)
Boost Exception responds to the following configuration macros:
'''BOOST_NO_RTTI'''\\
'''BOOST_NO_TYPEID'''
The first macro prevents Boost Exception from using dynamic_cast and dynamic typeid. If the second macro is also defined, Boost Exception does not use static typeid either. There are no observable degrading effects on the library functionality, except for the following:
->By default, the (:link
- 1
-
- 0
-
- -57
-
-
- 2
- :) function template can be called with any exception type. If BOOST_NO_RTTI is defined, (:link
- 1
-
- 0
-
- -57
-
-
- 2
- :) can be used only with objects of type boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :).
!!!!Note:
The library needs RTTI functionality. Disabling the language RTTI support enables an internal RTTI system, which may have more or less overhead depending on the platform.
'''BOOST_EXCEPTION_DISABLE'''
By default, (:link
- 1
-
- 0
-
- -37
-
-
- 2
- :) and (:link
- 1
-
- 0
-
- -26
-
-
- 2
- :) are integrated directly in the (:link
- 1
-
- 0
-
- -35
-
-
- 2
- :) function. Defining BOOST_EXCEPTION_DISABLE disables this integration.
Note that on some non-conformant compilers, for example MSVC 7.0 and older, as well as BCC, BOOST_EXCEPTION_DISABLE is implicitly defined in (:link
- 1
-
- 0
-
- -9
-
-
- 2
- :).
'''BOOST_NO_EXCEPTIONS'''
This macro disables exception handling in Boost, forwarding all exceptions to a user-defined non-template version of boost::
- 1
-
- 0
-
- -35
-
-
- 2
- . However, unless BOOST_EXCEPTION_DISABLE is also defined, users can still examine the exception object for any data added at the point of the throw, or use boost::
- 1
-
- 0
-
- -30
-
-
- 2
- (of course under BOOST_NO_EXCEPTIONS, the user-defined boost::throw_exception is not allowed to return to the caller.)
-
-
-
-
- 0
-
- -32
-
-
-
- 7
- 2
- (:auto !!!:)
(:include synopsis:)
This macro takes an exception object, records BOOST_CURRENT_FUNCTION, __FILE__ and __LINE__ in it, and forwards it to
- 1
-
- 0
-
- -35
-
-
- 2
- . To recover this information at the catch site, use
- 1
-
- 0
-
- -57
-
-
- 2
- ; the information is also included in the message returned by
- 1
-
- 0
-
- -30
-
-
- 2
- .
-
-
-
-
- 0
-
- -33
-
-
-
- 19
- 2
- (:auto !!!:)
(:include synopsis:)
The (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) type can be used to refer to a copy of an exception object. It is Default Constructible, Copy Constructible, Assignable and Equality Comparable; (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :)'s operations do not throw.
The referenced object remains valid at least as long as there is an
- 1
-
- 0
-
- -33
-
-
- 2
- object that refers to it.
Two instances of (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) are equivalent and compare equal if and only if they refer to the same exception.
The default constructor of (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) produces the null value of the type. The null value is equivalent only to itself.
!!!!Thread safety
* It is legal for multiple threads to hold (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) references to the same exception object.
* It is illegal for multiple threads to modify the same (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) object concurrently.
* While calling (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) makes a copy of the current exception object, it is still possible for the two copies to share internal state. Therefore, in general it is not safe to call (:link
- 1
-
- 0
-
- -39
-
-
- 2
- :) concurrently to throw the same exception object into multiple threads.
-
-
-
-
- 0
-
- -34
-
-
-
- 33
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
The (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) function must not be called outside of a catch block.
!!!!Returns:
* An (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) that refers to the currently handled exception or a copy of the currently handled exception.
* If the function needs to allocate memory and the attempt fails, it returns an (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) that refers to an instance of std::bad_alloc.
!!!!Throws:
Nothing.
!!!!Notes:
* It is unspecified whether the return values of two successive calls to (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) refer to the same exception object.
* Correct implementation of (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) may require compiler support, unless (:link
- 1
-
- 0
-
- -37
-
-
- 2
- :) was used at the time the currently handled exception object was passed to throw. Whenever
- 1
-
- 0
-
- -34
-
-
- 2
- fails to properly copy the current exception object, it returns an
- 1
-
- 0
-
- -33
-
-
- 2
- to an object of type that is as close as possible to the original exception type, using
- 1
-
- 0
-
- -28
-
-
- 2
- as a final fallback. All such types derive from boost::
- 1
-
- 0
-
- -47
-
-
- 2
- , and:
** if the original exception object derives from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :), then the boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) sub-object of the object referred to by the returned
- 1
-
- 0
-
- -33
-
-
- 2
- is initialized by the boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) copy constructor;
** if available, the exception contains the std::type_info of the original exception object, accessible through
- 1
-
- 0
-
- -57
-
-
- 2
- <
- 1
-
- 0
-
- -22
-
-
- 2
- >.
-
-
-
-
- 0
-
- -35
-
-
-
- 17
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
E must derive publicly from std::exception.
!!!!Effects:
* If BOOST_NO_EXCEPTIONS is not defined, boost::(:link
- 1
-
- 0
-
- -35
-
-
- 2
- :)(e) is equivalent to throw boost::(:link
- 1
-
- 0
-
- -37
-
-
- 2
- :)(boost::(:link
- 1
-
- 0
-
- -26
-
-
- 2
- :)(e)), unless BOOST_EXCEPTION_DISABLE is defined, in which case boost::(:link
- 1
-
- 0
-
- -35
-
-
- 2
- :)(e) is equivalent to throw e;
* If BOOST_NO_EXCEPTIONS is defined, the function is left undefined, and the user is expected to supply an appropriate definition. Callers of (:link
- 1
-
- 0
-
- -35
-
-
- 2
- :) are allowed to assume that the function never returns; therefore, if the user-defined (:link
- 1
-
- 0
-
- -35
-
-
- 2
- :) returns, the behavior is undefined.
!!!!Note:
Under BOOST_NO_EXCEPTIONS, unless BOOST_EXCEPTION_DISABLE is also defined, users can examine the passed exception object using boost::
- 1
-
- 0
-
- -57
-
-
- 2
- , or format an automatic diagnostic message using boost::
- 1
-
- 0
-
- -30
-
-
- 2
- .
-
-
-
-
- 0
-
- -36
-
-
-
- 3
- 2
- (:auto !!!:)
(:include decl:)
!!!!Effects:
Frees all resources associated with a boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) object.
!!!!Throws:
Nothing.
-
-
-
-
- 0
-
- -37
-
-
-
- 21
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
* T must be a class with an accessible no-throw copy constructor.
* If T has any virtual base types, those types must have an accessible default constructor.
!!!!Returns:
An object of ''unspecified'' type which derives publicly from T. That is, the returned object can be intercepted by a catch(T &).
!!!!Description:
This function is designed to be used directly in a throw-expression to enable the (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) support in Boost Exception. For example:
[@class
my_exception:
public std::exception
{
};
....
throw boost::(:link
- 1
-
- 0
-
- -37
-
-
- 2
- :)(my_exception());@]
Unless (:link
- 1
-
- 0
-
- -37
-
-
- 2
- :) is called at the time an exception object is used in a throw-expression, an attempt to copy it using (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) may return an (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) which refers to an instance of (:link
- 1
-
- 0
-
- -28
-
-
- 2
- :). See (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) for details.
!!!!Note:
Instead of using the throw keyword directly, it is preferable to call boost::(:link
- 1
-
- 0
-
- -35
-
-
- 2
- :). This is guaranteed to throw an exception that derives from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) and supports the (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) functionality.
-
-
-
-
- 0
-
- -38
-
-
-
- 13
- 2
- (:auto !!!:)
The code snippet below demonstrates how boost::(:link http://www.boost.org/libs/tuple/doc/tuple_users_guide.html|tuple:) can be used to bundle the name of the function that failed, together with the reported errno so that they can be added to exception objects more conveniently together:
[@#include <(:link
- 1
-
- 0
-
- -13
-
-
- 2
- :)>
#include <boost/shared_ptr.hpp>
#include <stdio.h>
#include <string>
#include <errno.h>
typedef boost::(:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<struct tag_file_name,std::string> file_name_info;
typedef boost::(:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<struct tag_function,char const *> function_info;
typedef boost::(:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<struct tag_errno,int> errno_info;
typedef boost::tuple<function_info,errno_info> clib_failure;
class file_open_error: public boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) { };
boost::shared_ptr<FILE>
file_open( char const * name, char const * mode )
{
if( FILE * f=fopen(name,mode) )
return boost::shared_ptr<FILE>(f,fclose);
else
throw file_open_error() <<
file_name_info(name) <<
clib_failure("fopen",errno);
}@]
Note that the members of a boost::(:link http://www.boost.org/libs/tuple/doc/tuple_users_guide.html|tuple:) are stored separately in exception objects; they can only be retrieved individually, using (:link
- 1
-
- 0
-
- -57
-
-
- 2
- :).
-
-
-
-
- 0
-
- -39
-
-
-
- 1
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Precondition:
ep shall not be null.
!!!!Throws:
The exception to which ep refers.
-
-
-
-
- 0
-
- -40
-
-
-
- 37
- 2
- (:auto !!!:)
When you catch an exception, you can call (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) to get an (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) object:
[@#include <(:link
- 1
-
- 0
-
- -16
-
-
- 2
- :)>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
void do_work(); //throws cloning-enabled boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :)s
void
worker_thread( boost::(:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) & error )
{
try
{
do_work();
error = boost::(:link
- 1
-
- 0
-
- -33
-
-
- 2
- :)();
}
catch(
... )
{
error = boost::(:link
- 1
-
- 0
-
- -34
-
-
- 2
- :)();
}
}@]
In the above example, note that (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) captures the original type of the exception object. The exception can be thrown again using the (:link
- 1
-
- 0
-
- -39
-
-
- 2
- :) function:
[@// ...continued
void
work()
{
boost::(:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) error;
boost::(:link http://www.boost.org/doc/html/boost/thread.html|thread:) t( boost::(:link http://www.boost.org/libs/bind/bind.html|bind:)(worker_thread,boost::(:link http://www.boost.org/doc/html/ref.html|ref:)(error)) );
t.(:link http://www.boost.org/doc/html/boost/thread.html|join:)();
if( error )
boost::(:link
- 1
-
- 0
-
- -39
-
-
- 2
- :)(error);
}@]
Note that (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) could fail to copy the original exception object in the following cases:
* if there is not enough memory, in which case the returned (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) points to an instance of std::bad_alloc, or
* if (:link
- 1
-
- 0
-
- -37
-
-
- 2
- :) was not used in the throw-expression passed to the original throw statement and the current implementation does not have the necessary compiler-specific support to copy the exception automatically, in which case the returned (:link
- 1
-
- 0
-
- -33
-
-
- 2
- :) points to an instance of (:link
- 1
-
- 0
-
- -28
-
-
- 2
- :).
Regardless, the use of (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :) and (:link
- 1
-
- 0
-
- -39
-
-
- 2
- :) in the above examples is well-formed.
-
-
-
-
- 0
-
- -41
-
-
-
- 1
- 2
- (:auto !!:)
(:pagelist fmt="index" tags="function":)
-
-
-
-
- 0
-
- -42
-
-
-
- 3
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Effects:
Stores a copy of v in the
- 1
-
- 0
-
- -52
-
-
- 2
- object.
(:include throws:)
-
-
-
-
- 0
-
- -43
-
-
-
- 5
- 2
- (:auto !!!:)
Exception types should use virtual inheritance when deriving from other exception types. This insight is due to Andrew Koenig. Using virtual inheritance prevents ambiguity problems in the exception handler:
[@#include <iostream>
struct my_exc1 : std::exception { char const* what() const throw(); };
struct my_exc2 : std::exception { char const* what() const throw(); };
struct your_exc3 : my_exc1, my_exc2 {};
int
main()
{
try { throw your_exc3(); }
catch(std::exception const& e) {}
catch(...) { std::cout << "whoops!" << std::endl; }
}@]
The program above outputs "whoops!" because the conversion to std::exception is ambiguous.
The overhead introduced by virtual inheritance is always negligible in the context of exception handling. Note that virtual bases are initialized directly by the constructor of the most-derived-type (the type passed to the throw statement, in case of exceptions.) However, typically this detail is of no concern when boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) is used, because it enables exception types to be trivial structs with no members (there's nothing to initialize.) See (:link
- 1
-
- 0
-
- -12
-
-
- 2
- mod="w":).
-
-
-
-
- 0
-
- -44
-
-
-
- 45
- 2
- !!Synopsis
List of documented definitions, declarations and includes by header file:
`#include <(:link
- 1
-
- 0
-
- -49
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -49
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -11
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -11
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -15
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -15
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -13
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -13
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -7
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -7
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -58
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -58
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -17
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -17
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -16
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -16
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -10
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -10
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -9
-
-
- 2
- :)>
[@(:include
- 1
-
- 0
-
- -9
-
-
- 2
- synopsis:)@]
`#include <(:link
- 1
-
- 0
-
- -5
-
-
- 2
- :)>
(:include
- 1
-
- 0
-
- -5
-
-
- 2
- synopsis:)
-
-
-
-
- 0
-
- -45
-
-
-
- 5
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
E must be boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :), or a type that derives (indirectly) from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :).
!!!!Effects:
Equivalent to x << v.(:link http://www.boost.org/libs/tuple/doc/tuple_users_guide.html#accessing_elements|get:)<0>() << ... << v.(:link http://www.boost.org/libs/tuple/doc/tuple_users_guide.html#accessing_elements|get:)<N>().
!!!!Returns:
x.
(:include throws:)
-
-
-
-
- 0
-
- -46
-
-
-
- 11
- 2
- (:auto !!:)
All exception types that derive from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) can be used as type-safe containers of arbitrary data objects, while complying with the no-throw requirements (15.5.1) of the ANSI C++ standard for exception types.
When exceptions derive from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :), arbitrary data can be added to exception objects:
*At the point of the throw;
*At a later time as exceptions bubble up the call stack.
(:include
- 1
-
- 0
-
- -27
-
-
- 2
- :)
(:include
- 1
-
- 0
-
- -48
-
-
- 2
- :)
(:include
- 1
-
- 0
-
- -38
-
-
- 2
- :)
-
-
-
-
- 0
-
- -47
-
-
-
- 13
- 2
- (:auto !!!:)
(:include synopsis:)
Class boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) is designed to be used as a universal base for user-defined exception types.
An object of any type deriving from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) can store data of arbitrary types, using the (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :) wrapper and (:link
- 1
-
- 0
-
- -56
-
-
- 2
- mod="/":).
To retrieve data from a boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) object, use the (:link
- 1
-
- 0
-
- -57
-
-
- 2
- :) function template.
-
-
-
-
- 0
-
- -48
-
-
-
- 19
- 2
- (:auto !!!:)
Sometimes the throw site does not have all the information that is needed at the catch site to make sense of what went wrong. Let's say we have an exception type file_read_error, which takes a file name in its constructor. Consider the following function:
[@void
file_read( FILE * f, void * buffer, size_t size )
{
if( size!=fread(buffer,1,size,f) )
throw file_read_error(????);
}@]
How can the file_read function pass a file name to the exception type constructor? All it has is a FILE handle.
Using boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) allows us to free the file_read function from the burden of storing the file name in exceptions it throws:
[@#include <(:link
- 1
-
- 0
-
- -5
-
-
- 2
- :)>
#include <stdio.h>
#include <errno.h>
typedef boost::(:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<struct tag_errno,int> errno_info;
class file_read_error: public boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) { };
void
file_read( FILE * f, void * buffer, size_t size )
{
if( size!=fread(buffer,1,size,f) )
throw file_read_error() << errno_info(errno);
}@]
If file_read detects a failure, it throws an exception which contains the information that is available at the time, namely the errno. Other relevant information, such as the file name, can be added in a context higher up the call stack, where it is known naturally:
[@#include <(:link
- 1
-
- 0
-
- -5
-
-
- 2
- :)>
#include <boost/shared_ptr.hpp>
#include <stdio.h>
#include <string>
typedef boost::(:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<struct tag_file_name,std::string> file_name_info;
boost::shared_ptr<FILE> file_open( char const * file_name, char const * mode );
void file_read( FILE * f, void * buffer, size_t size );
void
parse_file( char const * file_name )
{
boost::shared_ptr<FILE> f = file_open(file_name,"rb");
assert(f);
try
{
char buf[1024];
file_read( f.get(), buf, sizeof(buf) );
}
catch(
boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) & e )
{
e << file_name_info(file_name);
throw;
}
}@]
The above function is (almost) exception-neutral -- if an exception is emitted by any function call within the try block, parse_file does not need to do any real work, but it intercepts any boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) object, stores the file name, and re-throws using a throw-expression with no operand (15.1.6). The rationale for catching any boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) object is that the file name is relevant to any failure that occurs in parse_file, ''even if the failure is unrelated to file I/O''.
-
-
-
-
- 0
-
- -49
-
-
-
- 1
- 2
- (:auto !!:)
!!!Synopsis
(:include synopsis:)
-
-
-
-
- 0
-
- -50
-
-
-
- 1
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
This function must not be called outside of a catch block.
!!!!Returns:
A pointer of type E to the current exception object, or null if the current exception object can not be converted to E *.
!!!!Throws:
Nothing.
-
-
-
-
- 0
-
- -51
-
-
-
- 5
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Effects:
As if
[@try
{
throw
- 1
-
- 0
-
- -37
-
-
- 2
- (e);
}
catch(...)
{
return (:link
- 1
-
- 0
-
- -34
-
-
- 2
- :)();
}@]
-
-
-
-
- 0
-
- -52
-
-
-
- 37
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
T must have accessible copy constructor and must not be a reference (there is no requirement that T's copy constructor does not throw.)
!!!!Description:
This class template is used to associate a Tag type with a value type T. Objects of type (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<Tag,T> can be passed to (:link
- 1
-
- 0
-
- -56
-
-
- 2
- mod="/":) to be stored in objects of type boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :).
!!!!Usage:
The header <(:link
- 1
-
- 0
-
- -11
-
-
- 2
- :)> provides a declaration of the (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :) template, which is sufficient for the purpose of typedefing an instance for specific Tag and T, for example:
[@#include <(:link
- 1
-
- 0
-
- -11
-
-
- 2
- :)>
struct tag_errno;
typedef boost::(:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<tag_errno,int> errno_info;@]
Or, the shorter equivalent:
[@#include <(:link
- 1
-
- 0
-
- -11
-
-
- 2
- :)>
typedef boost::(:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)<struct tag_errno,int> errno_info;@]
This errno_info typedef can be passed to (:link
- 1
-
- 0
-
- -56
-
-
- 2
- mod="/":) (#include <(:link
- 1
-
- 0
-
- -15
-
-
- 2
- :)> first) to store an int named tag_errno in exceptions of types that derive from boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :):
[@throw file_read_error() (:link
- 1
-
- 0
-
- -56
-
-
- 2
- |<<:) errno_info(errno);@]
It can also be passed to (:link
- 1
-
- 0
-
- -57
-
-
- 2
- :) (#include <(:link
- 1
-
- 0
-
- -53
-
-
- 2
- :)> first) to retrieve the tag_errno int from a boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :):
[@catch( boost::(:link
- 1
-
- 0
-
- -47
-
-
- 2
- :) & x )
{
if( int const * e=boost::(:link
- 1
-
- 0
-
- -57
-
-
- 2
- :)<errno_info>(x) )
....
}@]
-
-
-
-
- 0
-
- -53
-
-
-
- 1
- 2
- (:auto !!:)
!!!Synopsis
(:include synopsis:)
-
-
-
-
- 0
-
- -54
-
-
-
- 69
- 2
- !!Introduction
The purpose of Boost Exception is to ease the design of exception class hierarchies and to help write exception handling and error reporting code.
It supports transporting of arbitrary data to the catch site, which is otherwise tricky due to the no-throw requirements (15.5.1) for exception types. Data can be added to any exception object, either directly in the throw-expression (15.1), or at a later time as the exception object propagates up the call stack.
The ability to add data to exception objects after they have been passed to throw is important, because often some of the information needed to handle an exception is unavailable in the context where the failure is detected.
Boost Exception also supports (:link http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2179.html|N2179:)-style (:link
- 1
-
- 0
-
- -60
-
-
- 2
- |copying:) of exception objects, implemented non-intrusively and automatically by the boost::(:link
- 1
-
- 0
-
- -35
-
-
- 2
- :) function.
!!Contents
#(:link
- 1
-
- 0
-
- -19
-
-
- 2
- :)
#Tutorial
##(:link
- 1
-
- 0
-
- -46
-
-
- 2
- mod="w":)
##(:link
- 1
-
- 0
-
- -20
-
-
- 2
- mod="w":)
##(:link
- 1
-
- 0
-
- -60
-
-
- 2
- mod="w":)
##(:link
- 1
-
- 0
-
- -12
-
-
- 2
- mod="w":)
##(:link
- 1
-
- 0
-
- -43
-
-
- 2
- mod="w":)
##(:link
- 1
-
- 0
-
- -29
-
-
- 2
- mod="w":)
#Documentation
##Class (:link
- 1
-
- 0
-
- -47
-
-
- 2
- :)
##Throwing Exceptions
###(:link
- 1
-
- 0
-
- -32
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -35
-
-
- 2
- :)
##Transporting of Arbitrary Data to the Catch Site
###(:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -56
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -45
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -57
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -26
-
-
- 2
- :)
##(:link http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2179.html|N2179:) Transporting of Exceptions between Threads
###(:link
- 1
-
- 0
-
- -33
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -37
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -34
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -51
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -39
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -28
-
-
- 2
- :)
##Diagnostic Information
###(:link
- 1
-
- 0
-
- -30
-
-
- 2
- :)
###(:link
- 1
-
- 0
-
- -61
-
-
- 2
- :)
##(:link
- 1
-
- 0
-
- -50
-
-
- 2
- :)
#API
##(:link
- 1
-
- 0
-
- -44
-
-
- 2
- :)
##(:link
- 1
-
- 0
-
- -23
-
-
- 2
- :)
##(:link
- 1
-
- 0
-
- -24
-
-
- 2
- :)
##(:link
- 1
-
- 0
-
- -41
-
-
- 2
- :)
##(:link
- 1
-
- 0
-
- -14
-
-
- 2
- :)
##(:link
- 1
-
- 0
-
- -31
-
-
- 2
- mod="w":)
#(:link
- 1
-
- 0
-
- -21
-
-
- 2
- mod="w":)
#(:link
- 1
-
- 0
-
- -18
-
-
- 2
- mod="w":)
!!!Acknowledgements
Thanks to Peter Dimov for his continuing help. Also thanks to Tobias Schwinger, Tom Brinkman, Pavel Vozenilek and everyone who participated in the review process.
-
-
-
-
- 0
-
- -55
-
-
-
- 5
- 2
- (:auto !!!:)
(:include synopsis:)
!!!!Description:
Returns a const reference to the copy of the value passed to (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :)'s constructor stored in the (:link
- 1
-
- 0
-
- -52
-
-
- 2
- :) object.
!!!!Throws:
Nothing.
-
-
-
-
- 0
-
- -21
+ -17
@@ -8681,6 +6121,2597 @@
|<<:) bar_info(bar);@]
which saves typing compared to this possible alternative:
[@error e;
e.add(foo_info(foo));
e.add(bar_info(bar));
throw e;@]
and looks better than something like:
[@throw error().add(foo_info(foo)).add(bar_info(bar));@]
+
+
+ 0
+
+ -18
+
+
+
+ 9
+ 2
+ (:auto !!!:)
(:include synopsis:)
This
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ typedef is used by
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ if it defaults to returning an
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ that refers to an object of type
+ 1
+
+ 0
+
+ -28
+
+
+ 2
+ , to record in it the std::type_info of the original exception object.
+
+
+
+
+ 0
+
+ -19
+
+
+
+ 1
+ 2
+ (:auto !!:)
(:pagelist fmt="index" tags="hpp" sort_prefix="6":)
+
+
+
+
+ 0
+
+ -20
+
+
+
+ 1
+ 2
+ (:auto !!:)
(:pagelist fmt="index" tags="type":)
+
+
+
+
+ 0
+
+ -21
+
+
+
+ 11
+ 2
+ (:auto !!!:)
Here is how cloning can be enabled in a throw-expression (15.1):
[@#include <(:link
+ 1
+
+ 0
+
+ -11
+
+
+ 2
+ :)>
#include <stdio.h>
#include <errno.h>
typedef boost::error_info<struct tag_errno,int> errno_info;
class file_read_error: public boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) { };
void
file_read( FILE * f, void * buffer, size_t size )
{
if( size!=fread(buffer,1,size,f) )
throw boost::(:link
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ :)(file_read_error()) <<
errno_info(errno);
}@]
Of course, (:link
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ :) may be used with any exception type; there is no requirement that it should derive from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :).
+
+
+
+
+ 0
+
+ -22
+
+
+
+ 1
+ 2
+ (:auto !!:)
!!!Synopsis
(:include synopsis:)
+
+
+
+
+ 0
+
+ -23
+
+
+
+ 5
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Definition:
The expression
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ <Tag,T>::(:link
+ 1
+
+ 0
+
+ -23
+
+
+ 2
+ mod="m":) evaluates to T.
+
+
+
+
+ 0
+
+ -24
+
+
+
+ 1
+ 2
+ (:auto !!!:)
!!!Synopsis
(:include synopsis:)
+
+
+
+
+ 0
+
+ -25
+
+
+
+ 3
+ 2
+ !!!!Example:
this is a possible output from the (:link
+ 1
+
+ 0
+
+ -30
+
+
+ 2
+ :) function, as used in ''libs/exception/example/example_io.cpp:''
[@example_io.cpp(83): Throw in function class boost::shared_ptr<struct _iobuf> __cdecl my_fopen(const char *,const char *)
Dynamic exception type: class boost::exception_detail::clone_impl<class fopen_error>
std::exception::what: example_io error
[struct tag_errno *] = 2, OS says "No such file or directory"
[struct tag_file_name *] = tmp1.txt
[struct tag_function *] = fopen
[struct tag_open_mode *] = rb@]
+
+
+
+
+ 0
+
+ -26
+
+
+
+ 5
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
T must be a class with an accessible no-throw copy constructor as per (15.5.1).
!!!!Returns:
* If T derives from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :), the returned object is of type T and is a copy of x.
* Otherwise, the returned object is of an unspecified type that derives publicly from both T and boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :). The T sub-object is initialized from x by the T copy constructor.
!!!!Throws:
Nothing.
+
+
+
+
+ 0
+
+ -27
+
+
+
+ 17
+ 2
+ (:auto !!!:)
The following example demonstrates how errno can be stored in exception objects using Boost Exception:
[@#include <(:link
+ 1
+
+ 0
+
+ -22
+
+
+ 2
+ :)>
#include <errno.h>
#include <iostream>
typedef boost::(:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<struct tag_errno,int> errno_info; //(1)
class my_error: public boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :), public std::exception { }; //(2)
void
f()
{
throw my_error() << errno_info(errno); //(3)
}
@]
First, we instantiate the (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :) template using a unique identifier -- tag_errno, and the type of the info it identifies -- int. This provides compile-time type safety for the various values stored in exception objects.
Second, we define class my_error, which derives from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :).
Finally, (3) illustrates how the typedef from (1) can be used with (:link
+ 1
+
+ 0
+
+ -56
+
+
+ 2
+ |operator<<:) to store values in exception objects at the point of the throw.
The stored errno value can be recovered at a later time like this:
[@// ...continued
void
g()
{
try
{
f();
}
catch(
my_error & x )
{
if( int const * err=boost::(:link
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ :)<errno_info>(x) )
std::cerr << "Error code: " << *err;
}
}@]
The (:link
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ :) function template is instantiated with the typedef from (1), and is passed an exception object of a polymorphic type. If the exception object contains the requested value, err will point to it; otherwise a null pointer is returned.
+
+
+
+
+ 0
+
+ -28
+
+
+
+ 5
+ 2
+ (:auto !!!:)
(:include synopsis:)
This type is used by the (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) support in Boost Exception. Please see (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :).
+
+
+
+
+ 0
+
+ -29
+
+
+
+ 19
+ 2
+ (:auto !!:)
Boost Exception provides a namespace-scope function (:link
+ 1
+
+ 0
+
+ -30
+
+
+ 2
+ :) which takes a boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :). The returned string contains:
*the string representation of all data objects added to the boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) through (:link
+ 1
+
+ 0
+
+ -56
+
+
+ 2
+ mod="/":);
*the output from std::exception::what;
*additional platform-specific diagnostic information.
The returned string is not presentable as a friendly user message, but because it is generated automatically, it is useful for debugging or logging purposes. Here is an example:
[@#include <(:link
+ 1
+
+ 0
+
+ -22
+
+
+ 2
+ :)>
#include <iostream>
void f(); //throws unknown types that derive from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :).
void
g()
{
try
{
f();
}
catch(
boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) & e )
{
std::cerr << (:link
+ 1
+
+ 0
+
+ -30
+
+
+ 2
+ :)(e);
}
}@]
(:include
+ 1
+
+ 0
+
+ -25
+
+
+ 2
+ :)
+
+
+
+
+ 0
+
+ -30
+
+
+
+ 29
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Returns:
A string value that contains varying amount of implementation-specific diagnostic information about the passed exception object:
*If E can be statically converted to boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :), the returned value contains the string representations of all (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :) objects stored in the boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) through (:link
+ 1
+
+ 0
+
+ -56
+
+
+ 2
+ mod="/":), along with other diagnostic information relevant to the exception. If e can be dynamically converted to std::exception, the returned value also contains the what() string.
*Otherwise, if E can be statically converted std::exception:
**if e can be dynamically converted to boost::exception, the returned value is the same as if E could be statically converted to boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :);
**otherwise the returned value contains the what() string.
*Otherwise, the boost::
+ 1
+
+ 0
+
+ -30
+
+
+ 2
+ template is not available.
The string representation of each (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :) object is deduced by a function call that is bound at the time the (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<Tag,T> template is instantiated. The following overload resolutions are attempted in order:
#Unqualified call to to_string(x), where x is of type (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<Tag,T> (the return value is expected to be of type std::string.)
#Unqualified call to to_string(x.(:link
+ 1
+
+ 0
+
+ -55
+
+
+ 2
+ mod="m":)()) (the return value is expected to be of type std::string.)
#Unqualified call to s << x.(:link
+ 1
+
+ 0
+
+ -55
+
+
+ 2
+ mod="m":)(), where s is a std::ostringstream.
The first successfully bound function is used at the time (:link
+ 1
+
+ 0
+
+ -30
+
+
+ 2
+ :) is called; if all 3 overload resolutions are unsuccessful, the system is unable to convert the (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :) object to string, and ''an unspecified stub string value is used without issuing a compile error.''
!!!!Notes:
*The format of the returned string is unspecified.
*The returned string is ''not'' user-friendly.
*The returned string may include additional platform-specific diagnostic information.
(:include
+ 1
+
+ 0
+
+ -25
+
+
+ 2
+ :)
+
+
+
+
+ 0
+
+ -31
+
+
+
+ 19
+ 2
+ (:auto !!:)
Boost Exception responds to the following configuration macros:
'''BOOST_NO_RTTI'''\\
'''BOOST_NO_TYPEID'''
The first macro prevents Boost Exception from using dynamic_cast and dynamic typeid. If the second macro is also defined, Boost Exception does not use static typeid either. There are no observable degrading effects on the library functionality, except for the following:
->By default, the (:link
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ :) function template can be called with any exception type. If BOOST_NO_RTTI is defined, (:link
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ :) can be used only with objects of type boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :).
!!!!Note:
The library needs RTTI functionality. Disabling the language RTTI support enables an internal RTTI system, which may have more or less overhead depending on the platform.
'''BOOST_EXCEPTION_DISABLE'''
By default, (:link
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ :) and (:link
+ 1
+
+ 0
+
+ -26
+
+
+ 2
+ :) are integrated directly in the (:link
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ :) function. Defining BOOST_EXCEPTION_DISABLE disables this integration.
Note that on some non-conformant compilers, for example MSVC 7.0 and older, as well as BCC, BOOST_EXCEPTION_DISABLE is implicitly defined in (:link
+ 1
+
+ 0
+
+ -5
+
+
+ 2
+ :).
'''BOOST_NO_EXCEPTIONS'''
This macro disables exception handling in Boost, forwarding all exceptions to a user-defined non-template version of boost::
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ . However, unless BOOST_EXCEPTION_DISABLE is also defined, users can still examine the exception object for any data added at the point of the throw, or use boost::
+ 1
+
+ 0
+
+ -30
+
+
+ 2
+ (of course under BOOST_NO_EXCEPTIONS, the user-defined boost::throw_exception is not allowed to return to the caller.)
+
+
+
+
+ 0
+
+ -32
+
+
+
+ 7
+ 2
+ (:auto !!!:)
(:include synopsis:)
This macro takes an exception object, records BOOST_CURRENT_FUNCTION, __FILE__ and __LINE__ in it, and forwards it to
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ . To recover this information at the catch site, use
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ ; the information is also included in the message returned by
+ 1
+
+ 0
+
+ -30
+
+
+ 2
+ .
+
+
+
+
+ 0
+
+ -33
+
+
+
+ 25
+ 2
+ (:auto !!!:)
(:include synopsis:)
The (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) type can be used to refer to a copy of an exception object. It is Default Constructible, Copy Constructible, Assignable and Equality Comparable; (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :)'s operations do not throw.
The referenced object remains valid at least as long as there is an (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) object that refers to it.
Two instances of (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) are equivalent and compare equal if and only if they refer to the same exception.
The default constructor of (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) produces the null value of the type. The null value is equivalent only to itself.
!!!!Thread safety
* It is legal for multiple threads to hold (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) references to the same exception object.
* It is illegal for multiple threads to modify the same (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) object concurrently.
* While calling (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) makes a copy of the current exception object, it is still possible for the two copies to share internal state. Therefore, in general it is not safe to call (:link
+ 1
+
+ 0
+
+ -39
+
+
+ 2
+ :) concurrently to throw the same exception object into multiple threads.
!!!!Nesting of exceptions
An
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ can be added as
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ to any boost::
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ . This is a convenient way to nest exceptions. There is no limit on the depth of the nesting, however cyclic references result in undefined behavior.
+
+
+
+
+ 0
+
+ -34
+
+
+
+ 33
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
The (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) function must not be called outside of a catch block.
!!!!Returns:
* An (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) that refers to the currently handled exception or a copy of the currently handled exception.
* If the function needs to allocate memory and the attempt fails, it returns an (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) that refers to an instance of std::bad_alloc.
!!!!Throws:
Nothing.
!!!!Notes:
* It is unspecified whether the return values of two successive calls to (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) refer to the same exception object.
* Correct implementation of (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) may require compiler support, unless (:link
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ :) was used at the time the currently handled exception object was passed to throw. Whenever
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ fails to properly copy the current exception object, it returns an
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ to an object of type that is as close as possible to the original exception type, using
+ 1
+
+ 0
+
+ -28
+
+
+ 2
+ as a final fallback. All such types derive from boost::
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ , and:
** if the original exception object derives from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :), then the boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) sub-object of the object referred to by the returned
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ is initialized by the boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) copy constructor;
** if available, the exception contains the std::type_info of the original exception object, accessible through
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ <
+ 1
+
+ 0
+
+ -18
+
+
+ 2
+ >.
+
+
+
+
+ 0
+
+ -35
+
+
+
+ 17
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
E must derive publicly from std::exception.
!!!!Effects:
* If BOOST_NO_EXCEPTIONS is not defined, boost::(:link
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ :)(e) is equivalent to throw boost::(:link
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ :)(boost::(:link
+ 1
+
+ 0
+
+ -26
+
+
+ 2
+ :)(e)), unless BOOST_EXCEPTION_DISABLE is defined, in which case boost::(:link
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ :)(e) is equivalent to throw e;
* If BOOST_NO_EXCEPTIONS is defined, the function is left undefined, and the user is expected to supply an appropriate definition. Callers of (:link
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ :) are allowed to assume that the function never returns; therefore, if the user-defined (:link
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ :) returns, the behavior is undefined.
!!!!Note:
Under BOOST_NO_EXCEPTIONS, unless BOOST_EXCEPTION_DISABLE is also defined, users can examine the passed exception object using boost::
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ , or format an automatic diagnostic message using boost::
+ 1
+
+ 0
+
+ -30
+
+
+ 2
+ .
+
+
+
+
+ 0
+
+ -36
+
+
+
+ 3
+ 2
+ (:auto !!!:)
(:include decl:)
!!!!Effects:
Frees all resources associated with a boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) object.
!!!!Throws:
Nothing.
+
+
+
+
+ 0
+
+ -37
+
+
+
+ 21
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
* T must be a class with an accessible no-throw copy constructor.
* If T has any virtual base types, those types must have an accessible default constructor.
!!!!Returns:
An object of ''unspecified'' type which derives publicly from T. That is, the returned object can be intercepted by a catch(T &).
!!!!Description:
This function is designed to be used directly in a throw-expression to enable the (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) support in Boost Exception. For example:
[@class
my_exception:
public std::exception
{
};
....
throw boost::(:link
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ :)(my_exception());@]
Unless (:link
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ :) is called at the time an exception object is used in a throw-expression, an attempt to copy it using (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) may return an (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) which refers to an instance of (:link
+ 1
+
+ 0
+
+ -28
+
+
+ 2
+ :). See (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) for details.
!!!!Note:
Instead of using the throw keyword directly, it is preferable to call boost::(:link
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ :). This is guaranteed to throw an exception that derives from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) and supports the (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) functionality.
+
+
+
+
+ 0
+
+ -38
+
+
+
+ 13
+ 2
+ (:auto !!!:)
The code snippet below demonstrates how boost::(:link http://www.boost.org/libs/tuple/doc/tuple_users_guide.html|tuple:) can be used to bundle the name of the function that failed, together with the reported errno so that they can be added to exception objects more conveniently together:
[@#include <(:link
+ 1
+
+ 0
+
+ -9
+
+
+ 2
+ :)>
#include <boost/shared_ptr.hpp>
#include <stdio.h>
#include <string>
#include <errno.h>
typedef boost::(:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<struct tag_file_name,std::string> file_name_info;
typedef boost::(:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<struct tag_function,char const *> function_info;
typedef boost::(:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<struct tag_errno,int> errno_info;
typedef boost::tuple<function_info,errno_info> clib_failure;
class file_open_error: public boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) { };
boost::shared_ptr<FILE>
file_open( char const * name, char const * mode )
{
if( FILE * f=fopen(name,mode) )
return boost::shared_ptr<FILE>(f,fclose);
else
throw file_open_error() <<
file_name_info(name) <<
clib_failure("fopen",errno);
}@]
Note that the members of a boost::(:link http://www.boost.org/libs/tuple/doc/tuple_users_guide.html|tuple:) are stored separately in exception objects; they can only be retrieved individually, using (:link
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ :).
+
+
+
+
+ 0
+
+ -39
+
+
+
+ 1
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Precondition:
ep shall not be null.
!!!!Throws:
The exception to which ep refers.
+
+
+
+
+ 0
+
+ -40
+
+
+
+ 37
+ 2
+ (:auto !!!:)
When you catch an exception, you can call (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) to get an (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) object:
[@#include <(:link
+ 1
+
+ 0
+
+ -12
+
+
+ 2
+ :)>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
void do_work(); //throws cloning-enabled boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :)s
void
worker_thread( boost::(:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) & error )
{
try
{
do_work();
error = boost::(:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :)();
}
catch(
... )
{
error = boost::(:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :)();
}
}@]
In the above example, note that (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) captures the original type of the exception object. The exception can be thrown again using the (:link
+ 1
+
+ 0
+
+ -39
+
+
+ 2
+ :) function:
[@// ...continued
void
work()
{
boost::(:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) error;
boost::(:link http://www.boost.org/doc/html/boost/thread.html|thread:) t( boost::(:link http://www.boost.org/libs/bind/bind.html|bind:)(worker_thread,boost::(:link http://www.boost.org/doc/html/ref.html|ref:)(error)) );
t.(:link http://www.boost.org/doc/html/boost/thread.html|join:)();
if( error )
boost::(:link
+ 1
+
+ 0
+
+ -39
+
+
+ 2
+ :)(error);
}@]
Note that (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) could fail to copy the original exception object in the following cases:
* if there is not enough memory, in which case the returned (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) points to an instance of std::bad_alloc, or
* if (:link
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ :) was not used in the throw-expression passed to the original throw statement and the current implementation does not have the necessary compiler-specific support to copy the exception automatically, in which case the returned (:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :) points to an instance of (:link
+ 1
+
+ 0
+
+ -28
+
+
+ 2
+ :).
Regardless, the use of (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :) and (:link
+ 1
+
+ 0
+
+ -39
+
+
+ 2
+ :) in the above examples is well-formed.
+
+
+
+
+ 0
+
+ -41
+
+
+
+ 1
+ 2
+ (:auto !!:)
(:pagelist fmt="index" tags="function":)
+
+
+
+
+ 0
+
+ -42
+
+
+
+ 3
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Effects:
Stores a copy of v in the
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ object.
(:include throws:)
+
+
+
+
+ 0
+
+ -43
+
+
+
+ 5
+ 2
+ (:auto !!!:)
Exception types should use virtual inheritance when deriving from other exception types. This insight is due to Andrew Koenig. Using virtual inheritance prevents ambiguity problems in the exception handler:
[@#include <iostream>
struct my_exc1 : std::exception { char const* what() const throw(); };
struct my_exc2 : std::exception { char const* what() const throw(); };
struct your_exc3 : my_exc1, my_exc2 {};
int
main()
{
try { throw your_exc3(); }
catch(std::exception const& e) {}
catch(...) { std::cout << "whoops!" << std::endl; }
}@]
The program above outputs "whoops!" because the conversion to std::exception is ambiguous.
The overhead introduced by virtual inheritance is always negligible in the context of exception handling. Note that virtual bases are initialized directly by the constructor of the most-derived-type (the type passed to the throw statement, in case of exceptions.) However, typically this detail is of no concern when boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) is used, because it enables exception types to be trivial structs with no members (there's nothing to initialize.) See (:link
+ 1
+
+ 0
+
+ -8
+
+
+ 2
+ mod="w":).
+
+
+
+
+ 0
+
+ -44
+
+
+
+ 45
+ 2
+ !!Synopsis
List of documented definitions, declarations and includes by header file:
`#include <(:link
+ 1
+
+ 0
+
+ -49
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -49
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -7
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -7
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -11
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -11
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -9
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -9
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -24
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -24
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -58
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -58
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -13
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -13
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -12
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -12
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -6
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -6
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -5
+
+
+ 2
+ :)>
[@(:include
+ 1
+
+ 0
+
+ -5
+
+
+ 2
+ synopsis:)@]
`#include <(:link
+ 1
+
+ 0
+
+ -22
+
+
+ 2
+ :)>
(:include
+ 1
+
+ 0
+
+ -22
+
+
+ 2
+ synopsis:)
+
+
+
+
+ 0
+
+ -45
+
+
+
+ 5
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
E must be boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :), or a type that derives (indirectly) from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :).
!!!!Effects:
Equivalent to x << v.(:link http://www.boost.org/libs/tuple/doc/tuple_users_guide.html#accessing_elements|get:)<0>() << ... << v.(:link http://www.boost.org/libs/tuple/doc/tuple_users_guide.html#accessing_elements|get:)<N>().
!!!!Returns:
x.
(:include throws:)
+
+
+
+
+ 0
+
+ -46
+
+
+
+ 11
+ 2
+ (:auto !!:)
All exception types that derive from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) can be used as type-safe containers of arbitrary data objects, while complying with the no-throw requirements (15.5.1) of the ANSI C++ standard for exception types.
When exceptions derive from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :), arbitrary data can be added to exception objects:
*At the point of the throw;
*At a later time as exceptions bubble up the call stack.
(:include
+ 1
+
+ 0
+
+ -27
+
+
+ 2
+ :)
(:include
+ 1
+
+ 0
+
+ -48
+
+
+ 2
+ :)
(:include
+ 1
+
+ 0
+
+ -38
+
+
+ 2
+ :)
+
+
+
+
+ 0
+
+ -47
+
+
+
+ 13
+ 2
+ (:auto !!!:)
(:include synopsis:)
Class boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) is designed to be used as a universal base for user-defined exception types.
An object of any type deriving from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) can store data of arbitrary types, using the (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :) wrapper and (:link
+ 1
+
+ 0
+
+ -56
+
+
+ 2
+ mod="/":).
To retrieve data from a boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) object, use the (:link
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ :) function template.
+
+
+
+
+ 0
+
+ -48
+
+
+
+ 19
+ 2
+ (:auto !!!:)
Sometimes the throw site does not have all the information that is needed at the catch site to make sense of what went wrong. Let's say we have an exception type file_read_error, which takes a file name in its constructor. Consider the following function:
[@void
file_read( FILE * f, void * buffer, size_t size )
{
if( size!=fread(buffer,1,size,f) )
throw file_read_error(????);
}@]
How can the file_read function pass a file name to the exception type constructor? All it has is a FILE handle.
Using boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) allows us to free the file_read function from the burden of storing the file name in exceptions it throws:
[@#include <(:link
+ 1
+
+ 0
+
+ -22
+
+
+ 2
+ :)>
#include <stdio.h>
#include <errno.h>
typedef boost::(:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<struct tag_errno,int> errno_info;
class file_read_error: public boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) { };
void
file_read( FILE * f, void * buffer, size_t size )
{
if( size!=fread(buffer,1,size,f) )
throw file_read_error() << errno_info(errno);
}@]
If file_read detects a failure, it throws an exception which contains the information that is available at the time, namely the errno. Other relevant information, such as the file name, can be added in a context higher up the call stack, where it is known naturally:
[@#include <(:link
+ 1
+
+ 0
+
+ -22
+
+
+ 2
+ :)>
#include <boost/shared_ptr.hpp>
#include <stdio.h>
#include <string>
typedef boost::(:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<struct tag_file_name,std::string> file_name_info;
boost::shared_ptr<FILE> file_open( char const * file_name, char const * mode );
void file_read( FILE * f, void * buffer, size_t size );
void
parse_file( char const * file_name )
{
boost::shared_ptr<FILE> f = file_open(file_name,"rb");
assert(f);
try
{
char buf[1024];
file_read( f.get(), buf, sizeof(buf) );
}
catch(
boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) & e )
{
e << file_name_info(file_name);
throw;
}
}@]
The above function is (almost) exception-neutral -- if an exception is emitted by any function call within the try block, parse_file does not need to do any real work, but it intercepts any boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) object, stores the file name, and re-throws using a throw-expression with no operand (15.1.6). The rationale for catching any boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) object is that the file name is relevant to any failure that occurs in parse_file, ''even if the failure is unrelated to file I/O''.
+
+
+
+
+ 0
+
+ -49
+
+
+
+ 1
+ 2
+ (:auto !!:)
!!!Synopsis
(:include synopsis:)
+
+
+
+
+ 0
+
+ -50
+
+
+
+ 1
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
This function must not be called outside of a catch block.
!!!!Returns:
A pointer of type E to the current exception object, or null if the current exception object can not be converted to E *.
!!!!Throws:
Nothing.
+
+
+
+
+ 0
+
+ -51
+
+
+
+ 5
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Effects:
As if
[@try
{
throw
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ (e);
}
catch(...)
{
return (:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :)();
}@]
+
+
+
+
+ 0
+
+ -52
+
+
+
+ 37
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Requirements:
T must have accessible copy constructor and must not be a reference (there is no requirement that T's copy constructor does not throw.)
!!!!Description:
This class template is used to associate a Tag type with a value type T. Objects of type (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<Tag,T> can be passed to (:link
+ 1
+
+ 0
+
+ -56
+
+
+ 2
+ mod="/":) to be stored in objects of type boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :).
!!!!Usage:
The header <(:link
+ 1
+
+ 0
+
+ -7
+
+
+ 2
+ :)> provides a declaration of the (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :) template, which is sufficient for the purpose of typedefing an instance for specific Tag and T, for example:
[@#include <(:link
+ 1
+
+ 0
+
+ -7
+
+
+ 2
+ :)>
struct tag_errno;
typedef boost::(:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<tag_errno,int> errno_info;@]
Or, the shorter equivalent:
[@#include <(:link
+ 1
+
+ 0
+
+ -7
+
+
+ 2
+ :)>
typedef boost::(:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)<struct tag_errno,int> errno_info;@]
This errno_info typedef can be passed to (:link
+ 1
+
+ 0
+
+ -56
+
+
+ 2
+ mod="/":) (#include <(:link
+ 1
+
+ 0
+
+ -11
+
+
+ 2
+ :)> first) to store an int named tag_errno in exceptions of types that derive from boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :):
[@throw file_read_error() (:link
+ 1
+
+ 0
+
+ -56
+
+
+ 2
+ |<<:) errno_info(errno);@]
It can also be passed to (:link
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ :) (#include <(:link
+ 1
+
+ 0
+
+ -53
+
+
+ 2
+ :)> first) to retrieve the tag_errno int from a boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :):
[@catch( boost::(:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :) & x )
{
if( int const * e=boost::(:link
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ :)<errno_info>(x) )
....
}@]
+
+
+
+
+ 0
+
+ -53
+
+
+
+ 1
+ 2
+ (:auto !!:)
!!!Synopsis
(:include synopsis:)
+
+
+
+
+ 0
+
+ -54
+
+
+
+ 69
+ 2
+ !!Introduction
The purpose of Boost Exception is to ease the design of exception class hierarchies and to help write exception handling and error reporting code.
It supports transporting of arbitrary data to the catch site, which is otherwise tricky due to the no-throw requirements (15.5.1) for exception types. Data can be added to any exception object, either directly in the throw-expression (15.1), or at a later time as the exception object propagates up the call stack.
The ability to add data to exception objects after they have been passed to throw is important, because often some of the information needed to handle an exception is unavailable in the context where the failure is detected.
Boost Exception also supports (:link http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2179.html|N2179:)-style (:link
+ 1
+
+ 0
+
+ -60
+
+
+ 2
+ |copying:) of exception objects, implemented non-intrusively and automatically by the boost::(:link
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ :) function.
!!Contents
#(:link
+ 1
+
+ 0
+
+ -15
+
+
+ 2
+ :)
#Tutorial
##(:link
+ 1
+
+ 0
+
+ -46
+
+
+ 2
+ mod="w":)
##(:link
+ 1
+
+ 0
+
+ -16
+
+
+ 2
+ mod="w":)
##(:link
+ 1
+
+ 0
+
+ -60
+
+
+ 2
+ mod="w":)
##(:link
+ 1
+
+ 0
+
+ -8
+
+
+ 2
+ mod="w":)
##(:link
+ 1
+
+ 0
+
+ -43
+
+
+ 2
+ mod="w":)
##(:link
+ 1
+
+ 0
+
+ -29
+
+
+ 2
+ mod="w":)
#Documentation
##Class (:link
+ 1
+
+ 0
+
+ -47
+
+
+ 2
+ :)
##Throwing Exceptions
###(:link
+ 1
+
+ 0
+
+ -32
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -35
+
+
+ 2
+ :)
##Transporting of Arbitrary Data to the Catch Site
###(:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -56
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -45
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -57
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -26
+
+
+ 2
+ :)
##(:link http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2179.html|N2179:) Transporting of Exceptions between Threads
###(:link
+ 1
+
+ 0
+
+ -33
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -37
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -34
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -51
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -39
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -28
+
+
+ 2
+ :)
##Diagnostic Information
###(:link
+ 1
+
+ 0
+
+ -30
+
+
+ 2
+ :)
###(:link
+ 1
+
+ 0
+
+ -61
+
+
+ 2
+ :)
##(:link
+ 1
+
+ 0
+
+ -50
+
+
+ 2
+ :)
#API
##(:link
+ 1
+
+ 0
+
+ -44
+
+
+ 2
+ :)
##(:link
+ 1
+
+ 0
+
+ -19
+
+
+ 2
+ :)
##(:link
+ 1
+
+ 0
+
+ -20
+
+
+ 2
+ :)
##(:link
+ 1
+
+ 0
+
+ -41
+
+
+ 2
+ :)
##(:link
+ 1
+
+ 0
+
+ -10
+
+
+ 2
+ :)
##(:link
+ 1
+
+ 0
+
+ -31
+
+
+ 2
+ mod="w":)
#(:link
+ 1
+
+ 0
+
+ -17
+
+
+ 2
+ mod="w":)
#(:link
+ 1
+
+ 0
+
+ -14
+
+
+ 2
+ mod="w":)
!!!Acknowledgements
Thanks to Peter Dimov for his continuing help. Also thanks to Tobias Schwinger, Tom Brinkman, Pavel Vozenilek and everyone who participated in the review process.
+
+
+
+
+ 0
+
+ -55
+
+
+
+ 5
+ 2
+ (:auto !!!:)
(:include synopsis:)
!!!!Description:
Returns a const reference to the copy of the value passed to (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :)'s constructor stored in the (:link
+ 1
+
+ 0
+
+ -52
+
+
+ 2
+ :) object.
!!!!Throws:
Nothing.
+
+
0
@@ -8883,7 +8914,7 @@
0
- -25
+ -21
2
@@ -9127,6 +9158,28 @@
0
+
+
+ 0
+
+ -20
+
+
+
+ 0
+
+
+
+
+ 0
+
+ -21
+
+
+
+ 0
+
+
0
@@ -9149,17 +9202,6 @@
0
-
-
- 0
-
- -20
-
-
-
- 0
-
-
0
@@ -9516,17 +9558,6 @@
0
-
-
- 0
-
- -21
-
-
-
- 0
-
-
0
@@ -9619,7 +9650,7 @@
1
2
- [@(:include api:)@]
+ (:include api:)
@@ -9629,28 +9660,6 @@
-6
-
- 3
- 2
- `#include <(:link
- 1
-
- 0
-
- -15
-
-
- 2
- :)>
[@(:include decl:)@]
-
-
-
-
- 0
-
- -7
-
-
3
2
@@ -9666,6 +9675,19 @@
>
namespace
boost
{
(:include api pre_indent="4":)
}@]
+
+
+ 0
+
+ -7
+
+
+
+ 1
+ 2
+ [@namespace
boost
{
(:include api pre_indent="4":)
}@]
+
+
0
@@ -9685,9 +9707,18 @@
- 1
+ 3
2
- (:include api:)
+ [@#include <
+ 1
+
+ 0
+
+ -11
+
+
+ 2
+ >
#include <boost/tuple/tuple.hpp>
namespace
boost
{
(:include api pre_indent="4":)
}@]
@@ -9698,18 +9729,7 @@
- 3
- 2
- [@#include <
- 1
-
- 0
-
- -49
-
-
- 2
- >
namespace
boost
{
(:include api pre_indent="4":)
}@]
+ 0
@@ -9720,9 +9740,18 @@
- 1
+ 3
2
- [@namespace
boost
{
(:include api pre_indent="4":)
}@]
+ [@#include <(:link
+ 1
+
+ 0
+
+ -49
+
+
+ 2
+ :)>
namespace
boost
{
(:include api pre_indent="4":)
}@]
@@ -9733,7 +9762,18 @@
- 0
+ 3
+ 2
+ [@#include <(:link
+ 1
+
+ 0
+
+ -49
+
+
+ 2
+ :)>
namespace
boost
{
(:include api pre_indent="4":)
}@]
@@ -9744,18 +9784,9 @@
- 3
+ 1
2
- [@#include <
- 1
-
- 0
-
- -15
-
-
- 2
- >
#include <boost/tuple/tuple.hpp>
namespace
boost
{
(:include api pre_indent="4":)
}@]
+ [@namespace
boost
{
(:include api pre_indent="4":)
}@]
@@ -9777,18 +9808,7 @@
- 3
- 2
- [@#include <(:link
- 1
-
- 0
-
- -49
-
-
- 2
- :)>
namespace
boost
{
(:include api pre_indent="4":)
}@]
+ 0
@@ -9799,18 +9819,7 @@
- 3
- 2
- [@#include <(:link
- 1
-
- 0
-
- -49
-
-
- 2
- :)>
namespace
boost
{
(:include api pre_indent="4":)
}@]
+ 0
@@ -9821,9 +9830,7 @@
- 1
- 2
- [@namespace
boost
{
(:include api pre_indent="4":)
}@]
+ 0
@@ -9833,28 +9840,6 @@
-18
-
- 0
-
-
-
-
- 0
-
- -19
-
-
-
- 0
-
-
-
-
- 0
-
- -22
-
-
3
2
@@ -9863,7 +9848,7 @@
0
- -16
+ -12
2
@@ -9874,7 +9859,7 @@
0
- -23
+ -19
@@ -9896,13 +9881,70 @@
0
- -24
+ -21
0
+
+
+ 0
+
+ -22
+
+
+
+ 1
+ 2
+ [@(:include api:)@]
+
+
+
+
+ 0
+
+ -23
+
+
+
+ 3
+ 2
+ `#include <(:link
+ 1
+
+ 0
+
+ -11
+
+
+ 2
+ :)>
[@(:include decl:)@]
+
+
+
+
+ 0
+
+ -24
+
+
+
+ 3
+ 2
+ [@#include <
+ 1
+
+ 0
+
+ -49
+
+
+ 2
+ >
namespace
boost
{
(:include api pre_indent="4":)
}@]
+
+
0
@@ -9929,7 +9971,7 @@
0
- -7
+ -24
2
@@ -9962,7 +10004,7 @@
0
- -16
+ -12
2
@@ -10028,7 +10070,7 @@
0
- -9
+ -5
2
@@ -10050,7 +10092,7 @@
0
- -16
+ -12
2
@@ -10072,7 +10114,7 @@
0
- -16
+ -12
2
@@ -10094,7 +10136,7 @@
0
- -9
+ -5
2
@@ -10127,7 +10169,7 @@
0
- -10
+ -6
2
@@ -10160,7 +10202,7 @@
0
- -16
+ -12
2
@@ -10204,7 +10246,7 @@
0
- -15
+ -11
2
@@ -10248,7 +10290,7 @@
0
- -13
+ -9
2
@@ -10336,7 +10378,7 @@
0
- -17
+ -13
2
@@ -10358,7 +10400,7 @@
0
- -16
+ -12
2
@@ -10380,7 +10422,7 @@
0
- -15
+ -11
2
@@ -10426,24 +10468,13 @@
0
- -15
+ -11
2
:)>
[@(:include decl:)@]
-
-
- 0
-
- -21
-
-
-
- 0
-
-
0
@@ -10459,7 +10490,7 @@
0
- -15
+ -11
2
@@ -10608,15 +10639,18 @@
-19
+
+ -20
+
+
+ -21
+
-22
-23
-
- -20
-
-24
@@ -10713,9 +10747,6 @@
-55
-
- -21
-
-56
@@ -10804,143 +10835,7 @@
- -18
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
- -7
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
- -10
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
- -19
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
- -43
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
- -12
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
- -21
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
- -41
-
-
-
-
-
-
- 0
-
-
-
-
-
- 1
-
-
-
- -23
+ -14
@@ -10974,7 +10869,143 @@
- -14
+ -6
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+ -15
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+ -43
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+ -8
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+ -17
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+ -41
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+ -19
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+ -20
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ 1
+
+
+
+ -10
@@ -10998,15 +11029,11 @@
- 2
- 7BD35FAECA8BDD2E78E08EB02CF7F36163AE21D6859C73267AC53A05E5797909
- 2464409114
- 3681
- 502
- DBE4A27FCB9297C314B3F52A460B55A5540B2A3F173D48C8CD042388D19253E2
- 263970566
- 3656
- 26
+ 1
+ 95AD55ACCB1C17C1DBA4C309BDFCBD4B66E52CD9A2F54FDAD2D642A00342D001
+ 3194412598
+ 4599
+ 323
@@ -11019,7 +11046,199 @@
- -30
+ -58
+
+
+
+
+
+
+ 1
+ 21E8093D2AF6946EAE135823066EF38B9DC8870432B44C81E585FF63A72F9903
+ 3352783584
+ 12170
+ 323
+
+
+
+
+
+ 0
+ ../../../../boost/exception_ptr.hpp
+ 0
+ 0
+
+
+
+ -12
+
+
+
+
+
+
+ 2
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
+ 6B3B617AC518A2177BDB89656E726B4E4D79577E289130493A61BAE24FB64838
+ 3173127726
+ 1101
+ 2184
+
+
+
+
+
+ 0
+ ../../../../boost/exception_ptr.hpp
+ 0
+ 0
+
+
+
+ -28
+
+
+
+
+
+
+ 2
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
+ E23085202D084CBB50F289988A6A592F06D923B77D0AB25D7A98A7188DF5BE3B
+ 1414247481
+ 766
+ 10094
+
+
+
+
+
+ 0
+ ../../../../boost/exception_ptr.hpp
+ 0
+ 0
+
+
+
+ -34
+
+
+
+
+
+
+ 2
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
+ AF894656AC8CED6190EEEE08B051DBF2106A393E313BB5BB1C17D4808EFED761
+ 1496105832
+ 1753
+ 429
+
+
+
+
+
+ 0
+ ../../../../boost/exception_ptr.hpp
+ 0
+ 0
+
+
+
+ -33
+
+
+
+
+
+
+ 2
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
+ 1516D0B7E11CBEB60CE4222565ACCAFF2E9857A8A505C1C26E2AE90087250581
+ 3624753243
+ 279
+ 26
+
+
+
+
+
+ 0
+ ../../../../boost/exception_ptr.hpp
+ 0
+ 0
+
+
+
+ -18
+
+
+
+
+
+
+ 2
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
+ B20A3D4631F3B2415EED1888B65FA33D7AED20F86BE196159D9297AAED115787
+ 3293519666
+ 117
+ 11169
+
+
+
+
+
+ 0
+ ../../../../boost/exception_ptr.hpp
+ 0
+ 0
+
+
+
+ -39
+
+
+
+
+
+
+ 2
+ CEB9022E39DA32E612158FF553D383E13D300D1202CEB754E28B716040EFC414
+ 1114955626
+ 11770
+ 723
+ 0066D4E6E6B189906E6DE04F08509F3737511701A1B1355B37511EC18E8371F4
+ 2078296250
+ 305
+ 10862
+
+
+
+
+
+ 0
+ ../../../../boost/exception_ptr.hpp
+ 0
+ 0
+
+
+
+ -51
@@ -11067,31 +11286,63 @@
- -8
+ -25
- 1
- B26AA4D68CD040C376C32D7D469C926EC02DB8F76A3DA3275D14CCABCA02902C
- 1262147856
- 4435
- 323
+ 2
+ AED5E79246B32BDF0E5C6CD8BDDC3370FD0BA1EFE3D4CE76C4A6D36A123F2E20
+ 228982966
+ 3918
+ 518
+ 6E325144EF4F41FA3A225EB30729101382C4E99B3D6160E307311E4B4E641010
+ 1097215175
+ 161
+ 240
0
- ../../../../boost/exception/diagnostic_information.hpp
+ ../../../../boost/exception/info.hpp
0
0
- -58
+ -42
+
+
+
+
+
+
+ 2
+ AED5E79246B32BDF0E5C6CD8BDDC3370FD0BA1EFE3D4CE76C4A6D36A123F2E20
+ 228982966
+ 3918
+ 518
+ D31BCE814DF5B8B718E7EB67A194AD08EF716A26D422E436596ABA1F145007D8
+ 4055211476
+ 525
+ 3387
+
+
+
+
+
+ 0
+ ../../../../boost/exception/info.hpp
+ 0
+ 0
+
+
+
+ -56
@@ -11115,7 +11366,7 @@
- -20
+ -16
@@ -11146,30 +11397,6 @@
-50
-
-
-
-
- 1
- ACBC114551B7A04441A0452AB97D25519D6D2AE97DA6C5DDBC2E7C4B9002F847
- 4238517159
- 11368
- 323
-
-
-
-
-
- 0
- ../../../../boost/exception_ptr.hpp
- 0
- 0
-
-
-
- -16
-
-
@@ -11198,6 +11425,62 @@
-57
+
+
+
+
+ 2
+ 02F77B8305279514F37A75FA6454AE750E04E7AA7934D395EFB52BCC7642965E
+ 430535365
+ 3379
+ 560
+ D08B74734CDA5115D9E47783E2994C2836BE241FB25E589BB4C67F2596727C03
+ 24341149
+ 3347
+ 26
+
+
+
+
+
+ 0
+ ../../../../boost/exception/diagnostic_information.hpp
+ 0
+ 0
+
+
+
+ -30
+
+
+
+
+
+
+ 2
+ D57BF77EE44CD2755E24A56DDC3E159716D04A7ABE009AE977D4926EFEC00F73
+ 2498368808
+ 973
+ 3941
+ 9432C669E21C649A86AC6DC5A34275B483A7D2D38118A462DF1C1CD7BBE5ED51
+ 2535426829
+ 441
+ 110
+
+
+
+
+
+ 0
+ ../../../../boost/exception/diagnostic_information.hpp
+ 0
+ 0
+
+
+
+ -61
+
+
@@ -11243,63 +11526,7 @@
- -5
-
-
-
-
-
-
- 2
- 1D3204D3ADDAB7AA716BEA1489EA852A9D6B5C110243364F6931FEF1CC2E5F88
- 422052608
- 3923
- 518
- 6E325144EF4F41FA3A225EB30729101382C4E99B3D6160E307311E4B4E641010
- 1097215175
- 161
- 240
-
-
-
-
-
- 0
- ../../../../boost/exception/info.hpp
- 0
- 0
-
-
-
- -42
-
-
-
-
-
-
- 2
- 1D3204D3ADDAB7AA716BEA1489EA852A9D6B5C110243364F6931FEF1CC2E5F88
- 422052608
- 3923
- 518
- D31BCE814DF5B8B718E7EB67A194AD08EF716A26D422E436596ABA1F145007D8
- 4055211476
- 525
- 3392
-
-
-
-
-
- 0
- ../../../../boost/exception/info.hpp
- 0
- 0
-
-
-
- -56
+ -22
@@ -11326,30 +11553,6 @@
-27
-
-
-
-
- 1
- A449DE2B3A2CDAE9DD932C06D224B3E07C95EBACBB4EA5890CA4CCF2DC74A693
- 1718307056
- 4118
- 323
-
-
-
-
-
- 0
- ../../../../boost/exception/info.hpp
- 0
- 0
-
-
-
- -15
-
-
@@ -11431,7 +11634,7 @@
- -17
+ -13
@@ -11491,7 +11694,7 @@
- -6
+ -23
@@ -11550,6 +11753,30 @@
-53
+
+
+
+
+ 1
+ 641BB230CEBF638811480BE0E3A96ABCB7CC9CC7E1C1A9C51FBAB296FFB6B7B1
+ 4248389286
+ 4113
+ 323
+
+
+
+
+
+ 0
+ ../../../../boost/exception/info.hpp
+ 0
+ 0
+
+
+
+ -11
+
+
@@ -11739,7 +11966,7 @@
- -13
+ -9
@@ -11763,7 +11990,7 @@
- -25
+ -21
@@ -11811,7 +12038,7 @@
- -9
+ -5
@@ -11838,174 +12065,6 @@
-48
-
-
-
-
- 2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
- 6B3B617AC518A2177BDB89656E726B4E4D79577E289130493A61BAE24FB64838
- 3173127726
- 1101
- 1777
-
-
-
-
-
- 0
- ../../../../boost/exception_ptr.hpp
- 0
- 0
-
-
-
- -28
-
-
-
-
-
-
- 2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
- E23085202D084CBB50F289988A6A592F06D923B77D0AB25D7A98A7188DF5BE3B
- 1414247481
- 766
- 9687
-
-
-
-
-
- 0
- ../../../../boost/exception_ptr.hpp
- 0
- 0
-
-
-
- -34
-
-
-
-
-
-
- 2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
- F86EB07D04CD0D0645080D1121DA899746D0C45137E17E1D9BE605E75396F047
- 1983537541
- 1346
- 429
-
-
-
-
-
- 0
- ../../../../boost/exception_ptr.hpp
- 0
- 0
-
-
-
- -33
-
-
-
-
-
-
- 2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
- 1516D0B7E11CBEB60CE4222565ACCAFF2E9857A8A505C1C26E2AE90087250581
- 3624753243
- 279
- 26
-
-
-
-
-
- 0
- ../../../../boost/exception_ptr.hpp
- 0
- 0
-
-
-
- -22
-
-
-
-
-
-
- 2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
- 0E9DF8366080712A816BE91ABCEF1E2044145B63D75B0B995B537900F378189E
- 1069696031
- 255
- 10762
-
-
-
-
-
- 0
- ../../../../boost/exception_ptr.hpp
- 0
- 0
-
-
-
- -39
-
-
-
-
-
-
- 2
- E73A20FFCA320C2129509D6916B42B4619582DCB5E6B204802AFA5DB176267EA
- 1330392285
- 11023
- 668
- 0066D4E6E6B189906E6DE04F08509F3737511701A1B1355B37511EC18E8371F4
- 2078296250
- 305
- 10455
-
-
-
-
-
- 0
- ../../../../boost/exception_ptr.hpp
- 0
- 0
-
-
-
- -51
-
-
@@ -12031,7 +12090,7 @@
- -11
+ -7
@@ -12086,30 +12145,6 @@
-38
-
-
-
-
- 1
- 683D57B85DAEB8F69927D079F2038E0C64853D2B8A8CB5273B76ACAD5901DDFD
- 878883983
- 573
- 4185
-
-
-
-
-
- 0
- ../../../../boost/exception/diagnostic_information.hpp
- 0
- 0
-
-
-
- -61
-
-
@@ -12147,7 +12182,7 @@
-6
- type
+ exception_ptr
@@ -12156,7 +12191,7 @@
-7
- error_info
+
@@ -12171,16 +12206,16 @@
0
- -10
+ -11
- exception_ptr
+
0
- -11
+ -12
@@ -12198,7 +12233,7 @@
0
- -15
+ -14
@@ -12210,16 +12245,7 @@
-16
-
-
-
-
- 0
-
- -17
-
-
-
+ tutorial
@@ -12228,7 +12254,16 @@
-18
-
+ type
+
+
+
+ 0
+
+ -21
+
+
+ noindex tutorial
@@ -12237,25 +12272,25 @@
-22
+
+
+
+
+ 0
+
+ -23
+
+
type
0
- -20
+ -24
- tutorial
-
-
-
- 0
-
- -25
-
-
- noindex tutorial
+ error_info
diff --git a/include/boost/exception/detail/exception_ptr_base.hpp b/include/boost/exception/detail/exception_ptr_base.hpp
new file mode 100644
index 0000000..1a17ff2
--- /dev/null
+++ b/include/boost/exception/detail/exception_ptr_base.hpp
@@ -0,0 +1,26 @@
+//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
+
+//Distributed under the Boost Software License, Version 1.0. (See accompanying
+//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef UUID_DC4208C6417811DEBF11E1EC55D89593
+#define UUID_DC4208C6417811DEBF11E1EC55D89593
+
+namespace
+boost
+ {
+ namespace
+ exception_detail
+ {
+ class
+ exception_ptr_base
+ {
+ public:
+
+ virtual void _rethrow() const=0;
+ virtual bool _empty() const=0;
+ };
+ }
+ }
+
+#endif
diff --git a/include/boost/exception/diagnostic_information.hpp b/include/boost/exception/diagnostic_information.hpp
index 2c66220..01f7b35 100644
--- a/include/boost/exception/diagnostic_information.hpp
+++ b/include/boost/exception/diagnostic_information.hpp
@@ -8,6 +8,7 @@
#include
#include
+#include
#include
#include
#include
@@ -41,16 +42,6 @@ boost
enum e { value = !enable_boost_exception_overload::value && sizeof(check((T*)0))==sizeof(yes) };
};
-#ifndef BOOST_NO_RTTI
- template
- inline
- std::string
- dynamic_exception_type( T const & x )
- {
- return std::string("Dynamic exception type: ") + BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name();
- }
-#endif
-
inline
char const *
get_diagnostic_information( exception const & x )
@@ -72,43 +63,41 @@ boost
inline
std::string
- boost_diagnostic_information( exception const & x )
+ diagnostic_information_impl( boost::exception const * be, std::exception const * se )
{
+ BOOST_ASSERT(be||se);
+#ifndef BOOST_NO_RTTI
+ if( !se )
+ se = dynamic_cast(be);
+ if( !be )
+ be = dynamic_cast(se);
+#endif
std::ostringstream tmp;
- if( char const * const * f=get_error_info(x) )
+ if( be )
{
- tmp << *f;
- if( int const * l=get_error_info(x) )
- tmp << '(' << *l << "): ";
+ if( char const * const * f=get_error_info(*be) )
+ {
+ tmp << *f;
+ if( int const * l=get_error_info(*be) )
+ tmp << '(' << *l << "): ";
+ }
+ tmp << "Throw in function ";
+ if( char const * const * fn=get_error_info(*be) )
+ tmp << *fn;
+ else
+ tmp << "(unknown)";
+ tmp << '\n';
}
- tmp << "Throw in function ";
- if( char const * const * fn=get_error_info(x) )
- tmp << *fn;
- else
- tmp << "(unknown)";
- tmp << std::endl;
#ifndef BOOST_NO_RTTI
- tmp << dynamic_exception_type(x) << std::endl;
- if( std::exception const * e=dynamic_cast(&x) )
- tmp << "std::exception::what: " << e->what() << std::endl;
+ tmp << std::string("Dynamic exception type: ") <<
+ (be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).name() << '\n';
#endif
- if( char const * s=exception_detail::get_diagnostic_information(x) )
- if( *s )
- tmp << s;
- return tmp.str();
- }
-
- inline
- std::string
- std_diagnostic_information( std::exception const & x )
- {
- std::ostringstream tmp;
-#ifndef BOOST_NO_RTTI
- if( exception const * e=dynamic_cast(&x) )
- return boost_diagnostic_information(*e);
- tmp << dynamic_exception_type(x) << std::endl;
-#endif
- tmp << "std::exception::what: " << x.what() << std::endl;
+ if( se )
+ tmp << "std::exception::what: " << se->what() << '\n';
+ if( be )
+ if( char const * s=exception_detail::get_diagnostic_information(*be) )
+ if( *s )
+ tmp << s;
return tmp.str();
}
}
@@ -118,7 +107,7 @@ boost
typename enable_if,std::string>::type
diagnostic_information( T const & e )
{
- return exception_detail::boost_diagnostic_information(e);
+ return exception_detail::diagnostic_information_impl(&e,0);
}
template
@@ -126,7 +115,7 @@ boost
typename enable_if,std::string>::type
diagnostic_information( T const & e )
{
- return exception_detail::std_diagnostic_information(e);
+ return exception_detail::diagnostic_information_impl(0,&e);
}
}
@@ -139,14 +128,31 @@ boost
std::string
current_exception_diagnostic_information()
{
- if( boost::exception const * e=current_exception_cast() )
- return diagnostic_information(*e);
- else if( std::exception const * e=current_exception_cast() )
- return diagnostic_information(*e);
+ boost::exception const * be=current_exception_cast();
+ std::exception const * se=current_exception_cast();
+ if( be || se )
+ return exception_detail::diagnostic_information_impl(be,se);
else
return "No diagnostic information available.";
}
- }
+
+ inline
+ std::string
+ diagnostic_information( exception_detail::exception_ptr_base const & p )
+ {
+ if( !p._empty() )
+ try
+ {
+ p._rethrow();
+ }
+ catch(
+ ... )
+ {
+ return current_exception_diagnostic_information();
+ }
+ return "";
+ }
+ }
#endif
#endif
diff --git a/include/boost/exception/info.hpp b/include/boost/exception/info.hpp
index 92a347e..3285638 100644
--- a/include/boost/exception/info.hpp
+++ b/include/boost/exception/info.hpp
@@ -106,7 +106,7 @@ boost
for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i )
{
shared_ptr const & x = i->second;
- tmp << '[' << x->tag_typeid_name() << "] = " << x->value_as_string() << std::endl;
+ tmp << '[' << x->tag_typeid_name() << "] = " << x->value_as_string() << '\n';
}
tmp.str().swap(diagnostic_info_str_);
}
diff --git a/include/boost/exception_ptr.hpp b/include/boost/exception_ptr.hpp
index c7a8ff5..91dce25 100644
--- a/include/boost/exception_ptr.hpp
+++ b/include/boost/exception_ptr.hpp
@@ -12,6 +12,7 @@
#endif
#include
#include
+#include
#include
#include
#include
@@ -37,7 +38,8 @@ boost
void rethrow_exception( exception_ptr const & );
class
- exception_ptr
+ exception_ptr:
+ public exception_detail::exception_ptr_base
{
typedef bool exception_ptr::*unspecified_bool_type;
friend exception_ptr current_exception();
@@ -65,6 +67,22 @@ boost
BOOST_ASSERT(c);
}
+ void
+ _rethrow() const
+ {
+ BOOST_ASSERT(*this);
+ if( bad_alloc_ )
+ throw enable_current_exception(std::bad_alloc());
+ else
+ c_->rethrow();
+ }
+
+ bool
+ _empty() const
+ {
+ return !bad_alloc_ && !c_;
+ }
+
public:
exception_ptr():
@@ -74,7 +92,7 @@ boost
operator unspecified_bool_type() const
{
- return (bad_alloc_ || c_) ? &exception_ptr::bad_alloc_ : 0;
+ return _empty() ? 0 : &exception_ptr::bad_alloc_;
}
friend
@@ -417,11 +435,26 @@ boost
void
rethrow_exception( exception_ptr const & p )
{
- BOOST_ASSERT(p);
- if( p.bad_alloc_ )
- throw enable_current_exception(std::bad_alloc());
- else
- p.c_->rethrow();
+ p._rethrow();
+ }
+
+ inline
+ std::string
+ to_string( exception_ptr const & p )
+ {
+ std::string s='\n'+diagnostic_information(p);
+ std::string padding(" ");
+ std::string r;
+ bool f=false;
+ for( std::string::const_iterator i=s.begin(),e=s.end(); i!=e; ++i )
+ {
+ if( f )
+ r+=padding;
+ char c=*i;
+ r+=c;
+ f=(c=='\n');
+ }
+ return r;
}
}
diff --git a/test/cloning_test.cpp b/test/cloning_test.cpp
index 11dea60..a54f58f 100644
--- a/test/cloning_test.cpp
+++ b/test/cloning_test.cpp
@@ -13,6 +13,8 @@
struct my_tag {};
#endif
+typedef boost::error_info nested_exception;
+
typedef boost::error_info my_info;
template
@@ -69,6 +71,17 @@ derives_std_boost_exception:
std::exception,
boost::exception
{
+ char const * const wh_;
+
+ derives_std_boost_exception( char const * wh="derives_std_boost_exception" ):
+ wh_(wh)
+ {
+ }
+
+ char const * what() const throw()
+ {
+ return wh_;
+ }
};
struct
@@ -530,5 +543,30 @@ main()
test_throw_on_copy();
test_throw_on_copy();
+ try
+ {
+ throw boost::enable_current_exception(derives_std_boost_exception("what1"));
+ }
+ catch(
+ ... )
+ {
+ boost::exception_ptr p=boost::current_exception();
+ {
+ std::string s=diagnostic_information(p);
+ BOOST_TEST(s.find("what1")!=s.npos);
+ }
+ try
+ {
+ throw boost::enable_current_exception(derives_std_boost_exception("what2") << nested_exception(p) );
+ }
+ catch(
+ ... )
+ {
+ std::string s=boost::current_exception_diagnostic_information();
+ BOOST_TEST(s.find("what1")!=s.npos);
+ BOOST_TEST(s.find("what2")!=s.npos);
+ }
+ }
+ BOOST_TEST(!diagnostic_information(boost::exception_ptr()).empty());
return boost::report_errors();
}