Alembic Version 1.1
ErrorHandler.h
Go to the documentation of this file.
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>
42
43namespace Alembic {
44namespace Abc {
45namespace ALEMBIC_VERSION_NS {
46
47//-*****************************************************************************
49{
50public:
51 enum Policy
52 {
55 kThrowPolicy
56 };
57
59 {
60 kUnknownException
61 };
62
64 : m_policy( kThrowPolicy )
65 , m_errorLog( "" ) {}
66
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
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
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//-*****************************************************************************
133
137
141
145
149
150//-*****************************************************************************
154
158
162
166
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
#define ALEMBIC_EXPORT
Definition: Export.h:51
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
Context(ErrorHandler &iEhnd, const char *iCtxMsg)
Definition: ErrorHandler.h:95
void operator()(const std::string &iErrMsg, const std::string &iCtx="")
void operator()(std::exception &iExc, const std::string &iCtx="")
void operator()(UnknownExceptionFlag iUef, const std::string &iCtx="")
Alembic::Util::shared_ptr< ArrayPropertyReader > ArrayPropertyReaderPtr
Alembic::Util::shared_ptr< ArchiveWriter > ArchiveWriterPtr
Smart Ptrs to Writers.
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr
Alembic::Util::shared_ptr< ObjectWriter > ObjectWriterPtr
Alembic::Util::shared_ptr< ObjectReader > ObjectReaderPtr
Alembic::Util::shared_ptr< ArrayPropertyWriter > ArrayPropertyWriterPtr
Alembic::Util::shared_ptr< ScalarPropertyReader > ScalarPropertyReaderPtr
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
Alembic::Util::shared_ptr< ArchiveReader > ArchiveReaderPtr
Smart Ptrs to Readers.
Alembic::Util::shared_ptr< ScalarPropertyWriter > ScalarPropertyWriterPtr
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
Alembic namespace ...
Definition: ArchiveInfo.h:46