Alembic: Abc/ErrorHandler.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
ErrorHandler.h
1//-*****************************************************************************
2//
3// Copyright (c) 2009-2013,
4// Sony Pictures Imageworks, Inc. and
5// Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6//
7// All rights reserved.
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12// * Redistributions of source code must retain the above copyright
13// notice, this list of conditions and the following disclaimer.
14// * Redistributions in binary form must reproduce the above
15// copyright notice, this list of conditions and the following disclaimer
16// in the documentation and/or other materials provided with the
17// distribution.
18// * Neither the name of Sony Pictures Imageworks, nor
19// Industrial Light & Magic nor the names of their contributors may be used
20// to endorse or promote products derived from this software without specific
21// prior written permission.
22//
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34//
35//-*****************************************************************************
36
37#ifndef Alembic_Abc_ErrorHandler_h
38#define Alembic_Abc_ErrorHandler_h
39
40#include <Alembic/Util/Export.h>
41#include <Alembic/Abc/Foundation.h>
42
43namespace Alembic {
44namespace Abc {
45namespace ALEMBIC_VERSION_NS {
46
47//-*****************************************************************************
48 class ALEMBIC_EXPORT ErrorHandler
49{
50public:
51 enum Policy
52 {
53 kQuietNoopPolicy,
54 kNoisyNoopPolicy,
55 kThrowPolicy
56 };
57
58 enum UnknownExceptionFlag
59 {
60 kUnknownException
61 };
62
63 ErrorHandler()
64 : m_policy( kThrowPolicy )
65 , m_errorLog( "" ) {}
66
67 ErrorHandler( Policy iPolicy )
68 : m_policy( iPolicy )
69 , m_errorLog( "" ) {}
70
73
74 void operator()( std::exception &iExc,
75 const std::string &iCtx = "" );
76
77 void operator()( const std::string &iErrMsg,
78 const std::string &iCtx = "" );
79
80 void operator()( UnknownExceptionFlag iUef,
81 const std::string &iCtx = "" );
82
83 Policy getPolicy() const { return m_policy; }
84 void setPolicy( Policy iPolicy ) { m_policy = iPolicy; }
85
86 const std::string getErrorLog() const { return m_errorLog; }
87
88 bool valid() const { return ( m_errorLog == "" ); }
89
90 void clear() { m_errorLog = ""; }
91
92 class Context
93 {
94 public:
95 Context( ErrorHandler &iEhnd, const char *iCtxMsg )
96 : m_handler( iEhnd ),
97 m_message( iCtxMsg ) {}
98
99 void operator()( std::exception &iExc )
100 {
101 m_handler( iExc, m_message );
102 }
103
104 void operator()( const std::string &iMsg )
105 {
106 m_handler( iMsg, m_message );
107 }
108
109 void operator()( UnknownExceptionFlag iUef )
110 {
111 m_handler( iUef, m_message );
112 }
113
114 private:
115 const Context& operator= (const Context&);
116 ErrorHandler &m_handler;
117 const char *m_message;
118 };
119
120private:
121 void handleIt( const std::string &iErr );
122
123 Policy m_policy;
124 std::string m_errorLog;
125};
126
127//-*****************************************************************************
128
129//-*****************************************************************************
130inline ErrorHandler::Policy
131GetErrorHandlerPolicy( AbcA::ArchiveWriterPtr /* iClass */ )
132{ return ErrorHandler::kThrowPolicy; }
133
134inline ErrorHandler::Policy
135GetErrorHandlerPolicy( AbcA::ObjectWriterPtr /* iClass */ )
136{ return ErrorHandler::kThrowPolicy; }
137
138inline ErrorHandler::Policy
139GetErrorHandlerPolicy( AbcA::CompoundPropertyWriterPtr /* iClass */ )
140{ return ErrorHandler::kThrowPolicy; }
141
142inline ErrorHandler::Policy
143GetErrorHandlerPolicy( AbcA::ScalarPropertyWriterPtr /* iClass */ )
144{ return ErrorHandler::kThrowPolicy; }
145
146inline ErrorHandler::Policy
147GetErrorHandlerPolicy( AbcA::ArrayPropertyWriterPtr /* iClass */ )
148{ return ErrorHandler::kThrowPolicy; }
149
150//-*****************************************************************************
151inline ErrorHandler::Policy
152GetErrorHandlerPolicy( AbcA::ArchiveReaderPtr /* iClass */ )
153{ return ErrorHandler::kThrowPolicy; }
154
155inline ErrorHandler::Policy
156GetErrorHandlerPolicy( AbcA::ObjectReaderPtr /* iClass */ )
157{ return ErrorHandler::kThrowPolicy; }
158
159inline ErrorHandler::Policy
160GetErrorHandlerPolicy( AbcA::CompoundPropertyReaderPtr /* iClass */ )
161{ return ErrorHandler::kThrowPolicy; }
162
163inline ErrorHandler::Policy
164GetErrorHandlerPolicy( AbcA::ScalarPropertyReaderPtr /* iClass */ )
165{ return ErrorHandler::kThrowPolicy; }
166
167inline ErrorHandler::Policy
168GetErrorHandlerPolicy( AbcA::ArrayPropertyReaderPtr /* iClass */ )
169{ return ErrorHandler::kThrowPolicy; }
170
171//-*****************************************************************************
172#define ALEMBIC_ABC_SAFE_CALL_BEGIN( CONTEXT ) \
173do \
174{ \
175 ::Alembic::Abc::ErrorHandler::Context \
176 __err( this->getErrorHandler(), ( CONTEXT ) ); \
177 try \
178 {
179
180//-*****************************************************************************
181#define ALEMBIC_ABC_SAFE_CALL_END_RESET() \
182 } \
183 catch ( std::exception &exc ) \
184 { \
185 this->reset(); \
186 __err( exc ); \
187 } \
188 catch ( ... ) \
189 { \
190 this->reset(); \
191 __err( ::Alembic::Abc:: \
192 ErrorHandler::kUnknownException ); \
193 } \
194} \
195while( 0 )
196
197//-*****************************************************************************
198#define ALEMBIC_ABC_SAFE_CALL_END() \
199 } \
200 catch ( std::exception &exc ) \
201 { \
202 __err( exc ); \
203 } \
204 catch ( ... ) \
205 { \
206 __err( ::Alembic::Abc:: \
207 ErrorHandler::kUnknownException ); \
208 } \
209} \
210while( 0 )
211
212} // End namespace ALEMBIC_VERSION_NS
213
214using namespace ALEMBIC_VERSION_NS;
215
216} // End namespace Abc
217} // End namespace Alembic
218
219#endif
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::operator()
void operator()(std::exception &iExc, const std::string &iCtx="")
Definition ErrorHandler.cpp:44
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39