Make all exceptions available.
parent
b7c789da67
commit
e1a0163e7e
|
@ -134,12 +134,12 @@ aiScene *BaseImporter::ReadFile(Importer *pImp, const std::string &pFile, IOSyst
|
||||||
// extract error description
|
// extract error description
|
||||||
m_ErrorText = err.what();
|
m_ErrorText = err.what();
|
||||||
ASSIMP_LOG_ERROR(m_ErrorText.c_str());
|
ASSIMP_LOG_ERROR(m_ErrorText.c_str());
|
||||||
|
m_exception = std::current_exception();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} catch( const std::exception& err ) {
|
} catch( const std::exception& err ) {
|
||||||
// extract error description
|
|
||||||
m_ErrorText = "Internal error";
|
m_ErrorText = "Internal error";
|
||||||
ASSIMP_LOG_ERROR(err.what());
|
ASSIMP_LOG_ERROR(err.what());
|
||||||
m_internalException = std::current_exception();
|
m_exception = std::current_exception();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -387,7 +387,7 @@ void Importer::FreeScene( ) {
|
||||||
pimpl->mScene = nullptr;
|
pimpl->mScene = nullptr;
|
||||||
|
|
||||||
pimpl->mErrorString = "";
|
pimpl->mErrorString = "";
|
||||||
pimpl->mInternalException = std::exception_ptr();
|
pimpl->mException = std::exception_ptr();
|
||||||
ASSIMP_END_EXCEPTION_REGION(void);
|
ASSIMP_END_EXCEPTION_REGION(void);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,11 +400,11 @@ const char* Importer::GetErrorString() const {
|
||||||
return pimpl->mErrorString.c_str();
|
return pimpl->mErrorString.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::exception_ptr& Importer::GetInternalException() const {
|
const std::exception_ptr& Importer::GetException() const {
|
||||||
ai_assert(nullptr != pimpl);
|
ai_assert(nullptr != pimpl);
|
||||||
|
|
||||||
// Must remain valid as long as ReadFile() or FreeFile() are not called
|
// Must remain valid as long as ReadFile() or FreeFile() are not called
|
||||||
return pimpl->mInternalException;
|
return pimpl->mException;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -434,7 +434,7 @@ aiScene* Importer::GetOrphanedScene() {
|
||||||
pimpl->mScene = nullptr;
|
pimpl->mScene = nullptr;
|
||||||
|
|
||||||
pimpl->mErrorString = ""; // reset error string
|
pimpl->mErrorString = ""; // reset error string
|
||||||
pimpl->mInternalException = std::exception_ptr();
|
pimpl->mException = std::exception_ptr();
|
||||||
ASSIMP_END_EXCEPTION_REGION(aiScene*);
|
ASSIMP_END_EXCEPTION_REGION(aiScene*);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
@ -511,7 +511,7 @@ const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
|
||||||
ReadFile(fbuff,pFlags);
|
ReadFile(fbuff,pFlags);
|
||||||
SetIOHandler(io);
|
SetIOHandler(io);
|
||||||
|
|
||||||
ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(const aiScene*, pimpl->mErrorString, pimpl->mInternalException);
|
ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(const aiScene*, pimpl->mErrorString, pimpl->mException);
|
||||||
return pimpl->mScene;
|
return pimpl->mScene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -718,7 +718,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) {
|
||||||
// if failed, extract the error string
|
// if failed, extract the error string
|
||||||
else if( !pimpl->mScene) {
|
else if( !pimpl->mScene) {
|
||||||
pimpl->mErrorString = imp->GetErrorText();
|
pimpl->mErrorString = imp->GetErrorText();
|
||||||
pimpl->mInternalException = imp->GetInternalException();
|
pimpl->mException = imp->GetException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear any data allocated by post-process steps
|
// clear any data allocated by post-process steps
|
||||||
|
@ -743,7 +743,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) {
|
||||||
#endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
|
#endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
|
||||||
|
|
||||||
// either successful or failure - the pointer expresses it anyways
|
// either successful or failure - the pointer expresses it anyways
|
||||||
ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(const aiScene*, pimpl->mErrorString, pimpl->mInternalException);
|
ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(const aiScene*, pimpl->mErrorString, pimpl->mException);
|
||||||
|
|
||||||
return pimpl->mScene;
|
return pimpl->mScene;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,11 +99,11 @@ public:
|
||||||
|
|
||||||
/** The error description, if there was one. In the case of a
|
/** The error description, if there was one. In the case of a
|
||||||
* failure not caused by a DeadlyImportError, mInternalException will
|
* failure not caused by a DeadlyImportError, mInternalException will
|
||||||
* carry the exception and this will be just "Internal error". */
|
* carry the full details and this will be just "Internal error". */
|
||||||
std::string mErrorString;
|
std::string mErrorString;
|
||||||
|
|
||||||
/** Any exception which wasn't a DeadlyImportError */
|
/** Any exception which occurred */
|
||||||
std::exception_ptr mInternalException;
|
std::exception_ptr mException;
|
||||||
|
|
||||||
/** List of integer properties */
|
/** List of integer properties */
|
||||||
IntPropertyMap mIntProperties;
|
IntPropertyMap mIntProperties;
|
||||||
|
@ -138,7 +138,7 @@ ImporterPimpl::ImporterPimpl() AI_NO_EXCEPT
|
||||||
, mPostProcessingSteps()
|
, mPostProcessingSteps()
|
||||||
, mScene( nullptr )
|
, mScene( nullptr )
|
||||||
, mErrorString()
|
, mErrorString()
|
||||||
, mInternalException()
|
, mException()
|
||||||
, mIntProperties()
|
, mIntProperties()
|
||||||
, mFloatProperties()
|
, mFloatProperties()
|
||||||
, mStringProperties()
|
, mStringProperties()
|
||||||
|
|
|
@ -151,12 +151,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns the exception of the last non-DeadlyImportError that occurred.
|
/** Returns the exception of the last exception that occurred.
|
||||||
* @return A description of the last error that occurred. An empty
|
* @return The last exception that occurred.
|
||||||
* string if there was no error.
|
|
||||||
*/
|
*/
|
||||||
const std::exception_ptr& GetInternalException() const {
|
const std::exception_ptr& GetException() const {
|
||||||
return m_internalException;
|
return m_exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
@ -423,8 +422,8 @@ protected:
|
||||||
/// Error description when a DeadlyImportError occurred during import.
|
/// Error description when a DeadlyImportError occurred during import.
|
||||||
/// In case of other errors, this will just be "Internal error"
|
/// In case of other errors, this will just be "Internal error"
|
||||||
std::string m_ErrorText;
|
std::string m_ErrorText;
|
||||||
/// Any exception which wasn't due to the asset being incorrect.
|
/// An exception which occurred.
|
||||||
std::exception_ptr m_internalException;
|
std::exception_ptr m_exception;
|
||||||
/// Currently set progress handler.
|
/// Currently set progress handler.
|
||||||
ProgressHandler *m_progress;
|
ProgressHandler *m_progress;
|
||||||
};
|
};
|
||||||
|
|
|
@ -140,15 +140,16 @@ struct ExceptionSwallower<void> {
|
||||||
{ \
|
{ \
|
||||||
try {
|
try {
|
||||||
|
|
||||||
#define ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(type, ASSIMP_END_EXCEPTION_REGION_errorString, ASSIMP_END_EXCEPTION_REGION_internalError) \
|
#define ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(type, ASSIMP_END_EXCEPTION_REGION_errorString, ASSIMP_END_EXCEPTION_REGION_exception) \
|
||||||
} \
|
} \
|
||||||
catch (const DeadlyImportError &e) { \
|
catch (const DeadlyImportError &e) { \
|
||||||
ASSIMP_END_EXCEPTION_REGION_errorString = e.what(); \
|
ASSIMP_END_EXCEPTION_REGION_errorString = e.what(); \
|
||||||
|
ASSIMP_END_EXCEPTION_REGION_exception = std::current_exception(); \
|
||||||
return ExceptionSwallower<type>()(); \
|
return ExceptionSwallower<type>()(); \
|
||||||
} \
|
} \
|
||||||
catch (...) { \
|
catch (...) { \
|
||||||
ASSIMP_END_EXCEPTION_REGION_errorString = "Internal error"; \
|
ASSIMP_END_EXCEPTION_REGION_errorString = "Internal error"; \
|
||||||
ASSIMP_END_EXCEPTION_REGION_internalError = std::current_exception(); \
|
ASSIMP_END_EXCEPTION_REGION_exception = std::current_exception(); \
|
||||||
return ExceptionSwallower<type>()(); \
|
return ExceptionSwallower<type>()(); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
|
@ -496,15 +496,13 @@ public:
|
||||||
const char *GetErrorString() const;
|
const char *GetErrorString() const;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns an internal exception if one occurred during import.
|
/** Returns an exception if one occurred during import.
|
||||||
*
|
*
|
||||||
* Returns the last non-DeadlyImportError exception which occurred.
|
* @return The last exception which occurred.
|
||||||
* @return The last exception which occurred which wasn't a
|
|
||||||
* DeadlyImportError.
|
|
||||||
*
|
*
|
||||||
* @note The returned value remains valid until one of the
|
* @note The returned value remains valid until one of the
|
||||||
* following methods is called: #ReadFile(), #FreeScene(). */
|
* following methods is called: #ReadFile(), #FreeScene(). */
|
||||||
const std::exception_ptr& GetInternalException() const;
|
const std::exception_ptr& GetException() const;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns the scene loaded by the last successful call to ReadFile()
|
/** Returns the scene loaded by the last successful call to ReadFile()
|
||||||
|
|
|
@ -334,7 +334,7 @@ TEST_F(ImporterTest, deadlyImportError)
|
||||||
const aiScene* scene = pImp->ReadFile("deadlyImportError.fail", 0);
|
const aiScene* scene = pImp->ReadFile("deadlyImportError.fail", 0);
|
||||||
EXPECT_EQ(scene, nullptr);
|
EXPECT_EQ(scene, nullptr);
|
||||||
EXPECT_STREQ(pImp->GetErrorString(), "Deadly import error test");
|
EXPECT_STREQ(pImp->GetErrorString(), "Deadly import error test");
|
||||||
EXPECT_EQ(pImp->GetInternalException(), std::exception_ptr());
|
EXPECT_NE(pImp->GetException(), std::exception_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ImporterTest, stdException)
|
TEST_F(ImporterTest, stdException)
|
||||||
|
@ -344,10 +344,10 @@ TEST_F(ImporterTest, stdException)
|
||||||
const aiScene* scene = pImp->ReadFile("stdException.fail", 0);
|
const aiScene* scene = pImp->ReadFile("stdException.fail", 0);
|
||||||
EXPECT_EQ(scene, nullptr);
|
EXPECT_EQ(scene, nullptr);
|
||||||
EXPECT_STREQ(pImp->GetErrorString(), "Internal error");
|
EXPECT_STREQ(pImp->GetErrorString(), "Internal error");
|
||||||
EXPECT_NE(pImp->GetInternalException(), std::exception_ptr());
|
EXPECT_NE(pImp->GetException(), std::exception_ptr());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::rethrow_exception(pImp->GetInternalException());
|
std::rethrow_exception(pImp->GetException());
|
||||||
}
|
}
|
||||||
catch(const std::exception& e)
|
catch(const std::exception& e)
|
||||||
{
|
{
|
||||||
|
@ -367,10 +367,10 @@ TEST_F(ImporterTest, unexpectedException)
|
||||||
|
|
||||||
EXPECT_EQ(scene, nullptr);
|
EXPECT_EQ(scene, nullptr);
|
||||||
EXPECT_STREQ(pImp->GetErrorString(), "Internal error");
|
EXPECT_STREQ(pImp->GetErrorString(), "Internal error");
|
||||||
ASSERT_NE(pImp->GetInternalException(), std::exception_ptr());
|
ASSERT_NE(pImp->GetException(), std::exception_ptr());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::rethrow_exception(pImp->GetInternalException());
|
std::rethrow_exception(pImp->GetException());
|
||||||
}
|
}
|
||||||
catch(int x)
|
catch(int x)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue