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