Loading...
Searching...
No Matches
ErrorHandler.h
Go to the documentation of this file.
//-*****************************************************************************
//
// Copyright (c) 2009-2013,
// Sony Pictures Imageworks, Inc. and
// Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Sony Pictures Imageworks, nor
// Industrial Light & Magic nor the names of their contributors may be used
// to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//-*****************************************************************************
#ifndef Alembic_Abc_ErrorHandler_h
#define Alembic_Abc_ErrorHandler_h
#include <Alembic/Util/Export.h>
#include <Alembic/Abc/Foundation.h>
namespace Alembic {
namespace Abc {
namespace ALEMBIC_VERSION_NS {
//-*****************************************************************************
class ALEMBIC_EXPORT ErrorHandler
{
public:
enum Policy
{
kQuietNoopPolicy,
kNoisyNoopPolicy,
kThrowPolicy
};
enum UnknownExceptionFlag
{
kUnknownException
};
ErrorHandler()
: m_policy( kThrowPolicy )
, m_errorLog( "" ) {}
ErrorHandler( Policy iPolicy )
: m_policy( iPolicy )
, m_errorLog( "" ) {}
void operator()( std::exception &iExc,
const std::string &iCtx = "" );
void operator()( const std::string &iErrMsg,
const std::string &iCtx = "" );
void operator()( UnknownExceptionFlag iUef,
const std::string &iCtx = "" );
Policy getPolicy() const { return m_policy; }
void setPolicy( Policy iPolicy ) { m_policy = iPolicy; }
const std::string getErrorLog() const { return m_errorLog; }
bool valid() const { return ( m_errorLog == "" ); }
void clear() { m_errorLog = ""; }
class Context
{
public:
Context( ErrorHandler &iEhnd, const char *iCtxMsg )
: m_handler( iEhnd ),
m_message( iCtxMsg ) {}
void operator()( std::exception &iExc )
{
m_handler( iExc, m_message );
}
void operator()( const std::string &iMsg )
{
m_handler( iMsg, m_message );
}
void operator()( UnknownExceptionFlag iUef )
{
m_handler( iUef, m_message );
}
private:
const Context& operator= (const Context&);
ErrorHandler &m_handler;
const char *m_message;
};
private:
void handleIt( const std::string &iErr );
Policy m_policy;
std::string m_errorLog;
};
//-*****************************************************************************
//-*****************************************************************************
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::ArchiveWriterPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::ObjectWriterPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::CompoundPropertyWriterPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::ScalarPropertyWriterPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::ArrayPropertyWriterPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
//-*****************************************************************************
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::ArchiveReaderPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::ObjectReaderPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::CompoundPropertyReaderPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::ScalarPropertyReaderPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
inline ErrorHandler::Policy
GetErrorHandlerPolicy( AbcA::ArrayPropertyReaderPtr /* iClass */ )
{ return ErrorHandler::kThrowPolicy; }
//-*****************************************************************************
#define ALEMBIC_ABC_SAFE_CALL_BEGIN( CONTEXT ) \
do \
{ \
::Alembic::Abc::ErrorHandler::Context \
__err( this->getErrorHandler(), ( CONTEXT ) ); \
try \
{
//-*****************************************************************************
#define ALEMBIC_ABC_SAFE_CALL_END_RESET() \
} \
catch ( std::exception &exc ) \
{ \
this->reset(); \
__err( exc ); \
} \
catch ( ... ) \
{ \
this->reset(); \
__err( ::Alembic::Abc:: \
ErrorHandler::kUnknownException ); \
} \
} \
while( 0 )
//-*****************************************************************************
#define ALEMBIC_ABC_SAFE_CALL_END() \
} \
catch ( std::exception &exc ) \
{ \
__err( exc ); \
} \
catch ( ... ) \
{ \
__err( ::Alembic::Abc:: \
ErrorHandler::kUnknownException ); \
} \
} \
while( 0 )
} // End namespace ALEMBIC_VERSION_NS
using namespace ALEMBIC_VERSION_NS;
} // End namespace Abc
} // End namespace Alembic
#endif
Foundation.h
Export.h
ALEMBIC_EXPORT
#define ALEMBIC_EXPORT
Definition Export.h:51
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::Context
Definition ErrorHandler.h:93
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::Context::operator()
void operator()(std::exception &iExc)
Definition ErrorHandler.h:99
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::Context::operator()
void operator()(UnknownExceptionFlag iUef)
Definition ErrorHandler.h:109
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::Context::Context
Context(ErrorHandler &iEhnd, const char *iCtxMsg)
Definition ErrorHandler.h:95
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::Context::operator()
void operator()(const std::string &iMsg)
Definition ErrorHandler.h:104
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::getPolicy
Policy getPolicy() const
Definition ErrorHandler.h:83
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::ErrorHandler
ErrorHandler()
Definition ErrorHandler.h:63
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::operator()
void operator()(const std::string &iErrMsg, const std::string &iCtx="")
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::setPolicy
void setPolicy(Policy iPolicy)
Definition ErrorHandler.h:84
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::operator()
void operator()(std::exception &iExc, const std::string &iCtx="")
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::clear
void clear()
Definition ErrorHandler.h:90
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::Policy
Policy
Definition ErrorHandler.h:52
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::kThrowPolicy
@ kThrowPolicy
Definition ErrorHandler.h:55
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::kNoisyNoopPolicy
@ kNoisyNoopPolicy
Definition ErrorHandler.h:54
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::kQuietNoopPolicy
@ kQuietNoopPolicy
Definition ErrorHandler.h:53
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::ErrorHandler
ErrorHandler(Policy iPolicy)
Definition ErrorHandler.h:67
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::getErrorLog
const std::string getErrorLog() const
Definition ErrorHandler.h:86
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::valid
bool valid() const
Definition ErrorHandler.h:88
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::UnknownExceptionFlag
UnknownExceptionFlag
Definition ErrorHandler.h:59
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::kUnknownException
@ kUnknownException
Definition ErrorHandler.h:60
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::operator()
void operator()(UnknownExceptionFlag iUef, const std::string &iCtx="")
Alembic::Abc::ALEMBIC_VERSION_NS
Definition ArchiveInfo.h:48
Alembic::Abc::ALEMBIC_VERSION_NS::GetErrorHandlerPolicy
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::Abc
Definition ArchiveInfo.h:47
Alembic
Alembic namespace ...
Definition ArchiveInfo.h:46