HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
41 #include <Alembic/Abc/Foundation.h>
42 
43 namespace Alembic {
44 namespace Abc {
45 namespace ALEMBIC_VERSION_NS {
46 
47 //-*****************************************************************************
49 {
50 public:
51  enum Policy
52  {
55  kThrowPolicy
56  };
57 
59  {
60  kUnknownException
61  };
62 
64  : m_policy( kThrowPolicy )
65  , m_errorLog( "" ) {}
66 
67  ErrorHandler( Policy iPolicy )
68  : m_policy( iPolicy )
69  , m_errorLog( "" ) {}
70 
71  //! Default copy constructor
72  //! Default assignment operator
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 std::string &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  std::string m_message;
118  };
119 
120 private:
121  void handleIt( const std::string &iErr );
122 
123  Policy m_policy;
124  std::string m_errorLog;
125 };
126 
127 //-*****************************************************************************
128 
129 //-*****************************************************************************
132 { return ErrorHandler::kThrowPolicy; }
133 
136 { return ErrorHandler::kThrowPolicy; }
137 
140 { return ErrorHandler::kThrowPolicy; }
141 
144 { return ErrorHandler::kThrowPolicy; }
145 
148 { return ErrorHandler::kThrowPolicy; }
149 
150 //-*****************************************************************************
153 { return ErrorHandler::kThrowPolicy; }
154 
157 { return ErrorHandler::kThrowPolicy; }
158 
161 { return ErrorHandler::kThrowPolicy; }
162 
165 { return ErrorHandler::kThrowPolicy; }
166 
169 { return ErrorHandler::kThrowPolicy; }
170 
171 //-*****************************************************************************
172 #define ALEMBIC_ABC_SAFE_CALL_BEGIN( CONTEXT ) \
173 do \
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 } \
195 while( 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 } \
210 while( 0 )
211 
212 } // End namespace ALEMBIC_VERSION_NS
213 
214 using namespace ALEMBIC_VERSION_NS;
215 
216 } // End namespace Abc
217 } // End namespace Alembic
218 
219 #endif
Alembic::Util::shared_ptr< ObjectWriter > ObjectWriterPtr
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
Alembic::Util::shared_ptr< ObjectReader > ObjectReaderPtr
Alembic::Util::shared_ptr< ArrayPropertyReader > ArrayPropertyReaderPtr
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
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::Util::shared_ptr< ArrayPropertyWriter > ArrayPropertyWriterPtr
Alembic::Util::shared_ptr< ScalarPropertyWriter > ScalarPropertyWriterPtr
Alembic::Util::shared_ptr< ArchiveReader > ArchiveReaderPtr
Smart Ptrs to Readers.
Context(ErrorHandler &iEhnd, const std::string &iCtxMsg)
Definition: ErrorHandler.h:95
Alembic::Util::shared_ptr< ScalarPropertyReader > ScalarPropertyReaderPtr
Alembic::Util::shared_ptr< ArchiveWriter > ArchiveWriterPtr
Smart Ptrs to Writers.
#define ALEMBIC_EXPORT
Definition: Export.h:51
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr