fix doc example typo
[boost.git] / boost / archive / archive_exception.hpp
bloba294a8979cc8b3ea7805f4b7e859bb1c5539e3df
1 #ifndef BOOST_ARCHIVE_ARCHIVE_EXCEPTION_HPP
2 #define BOOST_ARCHIVE_ARCHIVE_EXCEPTION_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
6 # pragma once
7 #endif
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // archive/archive_exception.hpp:
12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
13 // Use, modification and distribution is subject to the Boost Software
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // See http://www.boost.org for updates, documentation, and revision history.
19 #include <exception>
20 #include <cassert>
22 namespace boost {
23 namespace archive {
25 //////////////////////////////////////////////////////////////////////
26 // exceptions thrown by archives
28 class archive_exception :
29 public virtual std::exception
31 public:
32 typedef enum {
33 no_exception, // initialized without code
34 other_exception, // any excepton not listed below
35 unregistered_class, // attempt to serialize a pointer of an
36 // an unregistered class
37 invalid_signature, // first line of archive does not contain
38 // expected string
39 unsupported_version,// archive created with library version
40 // subsequent to this one
41 pointer_conflict, // an attempt has been made to directly
42 // serialization::detail an object
43 // after having already serialzed the same
44 // object through a pointer. Were this permited,
45 // it the archive load would result in the
46 // creation of an extra copy of the obect.
47 incompatible_native_format, // attempt to read native binary format
48 // on incompatible platform
49 array_size_too_short,// array being loaded doesn't fit in array allocated
50 stream_error, // i/o error on stream
51 invalid_class_name, // class name greater than the maximum permitted.
52 // most likely a corrupted archive or an attempt
53 // to insert virus via buffer overrun method.
54 unregistered_cast, // base - derived relationship not registered with
55 // void_cast_register
56 unsupported_class_version // type saved with a version # greater than the
57 // one used by the program. This indicates that the proggram
58 // needs to be rebuilt.
59 } exception_code;
60 exception_code code;
61 archive_exception(exception_code c) :
62 code(c)
64 virtual const char *what( ) const throw( )
66 const char *msg = "programming error";
67 switch(code){
68 case no_exception:
69 msg = "uninitialized exception";
70 break;
71 case unregistered_class:
72 msg = "unregistered class";
73 break;
74 case invalid_signature:
75 msg = "invalid signature";
76 break;
77 case unsupported_version:
78 msg = "unsupported version";
79 break;
80 case pointer_conflict:
81 msg = "pointer conflict";
82 break;
83 case incompatible_native_format:
84 msg = "incompatible native format";
85 break;
86 case array_size_too_short:
87 msg = "array size too short";
88 break;
89 case stream_error:
90 msg = "stream error";
91 break;
92 case invalid_class_name:
93 msg = "class name too long";
94 break;
95 case unregistered_cast:
96 msg = "unregistered void cast";
97 break;
98 case unsupported_class_version:
99 msg = "class version";
100 break;
101 case other_exception:
102 // if get here - it indicates a derived exception
103 // was sliced by passing by value in catch
104 msg = "unknown derived exception";
105 break;
106 default:
107 assert(false);
108 break;
110 return msg;
112 protected:
113 archive_exception() :
114 code(no_exception)
118 }// namespace archive
119 }// namespace boost
121 #endif //BOOST_ARCHIVE_ARCHIVE_EXCEPTION_HPP