1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
2 | // archive_exception.cpp: |
3 | |
4 | // (C) Copyright 2009 Robert Ramey - http://www.rrsd.com . |
5 | // Use, modification and distribution is subject to the Boost Software |
6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
7 | // http://www.boost.org/LICENSE_1_0.txt) |
8 | |
9 | // See http://www.boost.org for updates, documentation, and revision history. |
10 | |
11 | #if (defined _MSC_VER) && (_MSC_VER == 1200) |
12 | # pragma warning (disable : 4786) // too long name, harmless warning |
13 | #endif |
14 | |
15 | #include <exception> |
16 | #include <string> |
17 | #include <cstring> |
18 | |
19 | #define BOOST_ARCHIVE_SOURCE |
20 | #include <boost/serialization/config.hpp> |
21 | #include <boost/archive/archive_exception.hpp> |
22 | |
23 | namespace boost { |
24 | namespace archive { |
25 | |
26 | BOOST_ARCHIVE_DECL |
27 | unsigned int |
28 | archive_exception::append(unsigned int l, const char * a){ |
29 | while(l < (sizeof(m_buffer) - 1)){ |
30 | char c = *a++; |
31 | if('\0' == c) |
32 | break; |
33 | m_buffer[l++] = c; |
34 | } |
35 | m_buffer[l] = '\0'; |
36 | return l; |
37 | } |
38 | |
39 | BOOST_ARCHIVE_DECL |
40 | archive_exception::archive_exception( |
41 | exception_code c, |
42 | const char * e1, |
43 | const char * e2 |
44 | ) BOOST_NOEXCEPT : |
45 | code(c) |
46 | { |
47 | unsigned int length = 0; |
48 | switch(code){ |
49 | case no_exception: |
50 | length = append(l: length, a: "uninitialized exception" ); |
51 | break; |
52 | case unregistered_class: |
53 | length = append(l: length, a: "unregistered class" ); |
54 | if(NULL != e1){ |
55 | length = append(l: length, a: " - " ); |
56 | length = append(l: length, a: e1); |
57 | } |
58 | break; |
59 | case invalid_signature: |
60 | length = append(l: length, a: "invalid signature" ); |
61 | break; |
62 | case unsupported_version: |
63 | length = append(l: length, a: "unsupported version" ); |
64 | break; |
65 | case pointer_conflict: |
66 | length = append(l: length, a: "pointer conflict" ); |
67 | break; |
68 | case incompatible_native_format: |
69 | length = append(l: length, a: "incompatible native format" ); |
70 | if(NULL != e1){ |
71 | length = append(l: length, a: " - " ); |
72 | length = append(l: length, a: e1); |
73 | } |
74 | break; |
75 | case array_size_too_short: |
76 | length = append(l: length, a: "array size too short" ); |
77 | break; |
78 | case input_stream_error: |
79 | length = append(l: length, a: "input stream error" ); |
80 | if(NULL != e1){ |
81 | length = append(l: length, a: "-" ); |
82 | length = append(l: length, a: e1); |
83 | } |
84 | if(NULL != e2){ |
85 | length = append(l: length, a: "-" ); |
86 | length = append(l: length, a: e2); |
87 | } |
88 | break; |
89 | case invalid_class_name: |
90 | length = append(l: length, a: "class name too long" ); |
91 | break; |
92 | case unregistered_cast: |
93 | length = append(l: length, a: "unregistered void cast " ); |
94 | length = append(l: length, a: (NULL != e1) ? e1 : "?" ); |
95 | length = append(l: length, a: "<-" ); |
96 | length = append(l: length, a: (NULL != e2) ? e2 : "?" ); |
97 | break; |
98 | case unsupported_class_version: |
99 | length = append(l: length, a: "class version " ); |
100 | length = append(l: length, a: (NULL != e1) ? e1 : "<unknown class>" ); |
101 | break; |
102 | case other_exception: |
103 | // if get here - it indicates a derived exception |
104 | // was sliced by passing by value in catch |
105 | length = append(l: length, a: "unknown derived exception" ); |
106 | break; |
107 | case multiple_code_instantiation: |
108 | length = append(l: length, a: "code instantiated in more than one module" ); |
109 | if(NULL != e1){ |
110 | length = append(l: length, a: " - " ); |
111 | length = append(l: length, a: e1); |
112 | } |
113 | break; |
114 | case output_stream_error: |
115 | length = append(l: length, a: "output stream error" ); |
116 | if(NULL != e1){ |
117 | length = append(l: length, a: "-" ); |
118 | length = append(l: length, a: e1); |
119 | } |
120 | if(NULL != e2){ |
121 | length = append(l: length, a: "-" ); |
122 | length = append(l: length, a: e2); |
123 | } |
124 | break; |
125 | default: |
126 | BOOST_ASSERT(false); |
127 | length = append(l: length, a: "programming error" ); |
128 | break; |
129 | } |
130 | } |
131 | |
132 | BOOST_ARCHIVE_DECL |
133 | archive_exception::archive_exception(archive_exception const & oth) BOOST_NOEXCEPT : |
134 | std::exception(oth), |
135 | code(oth.code) |
136 | { |
137 | std::memcpy(dest: m_buffer,src: oth.m_buffer,n: sizeof m_buffer); |
138 | } |
139 | |
140 | BOOST_ARCHIVE_DECL |
141 | archive_exception::~archive_exception() BOOST_NOEXCEPT_OR_NOTHROW {} |
142 | |
143 | BOOST_ARCHIVE_DECL const char * |
144 | archive_exception::what() const BOOST_NOEXCEPT_OR_NOTHROW { |
145 | return m_buffer; |
146 | } |
147 | |
148 | BOOST_ARCHIVE_DECL |
149 | archive_exception::archive_exception() BOOST_NOEXCEPT : |
150 | code(no_exception) |
151 | {} |
152 | |
153 | } // archive |
154 | } // boost |
155 | |