diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2001-03-10 03:59:46 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2001-03-10 03:59:46 (GMT) |
commit | 9cd9f7f5216fbc30b10426f5bd11e26d81668eac (patch) | |
tree | be3e4f25e5a870f8e98c7b1cfce3917a5dd19269 /c++/src/H5Exception.cpp | |
parent | cd29e12e0252ccfc969281c5dabd991b46203f05 (diff) | |
download | hdf5-9cd9f7f5216fbc30b10426f5bd11e26d81668eac.zip hdf5-9cd9f7f5216fbc30b10426f5bd11e26d81668eac.tar.gz hdf5-9cd9f7f5216fbc30b10426f5bd11e26d81668eac.tar.bz2 |
[svn-r3602]
Purpose: Usability enhancement
Description:
- Added more information about the failure to all the throw's,
i.e, member function name and more detail about the failure, where
appropriate. Also, added exception throws for private functions,
such as p_close to provide more specific details.
- Added two api functions: Exception::getFuncName() and
Exception::getCFuncName() to provide the name of the member
function where failure occurs.
- Fixed some typos, one of which caused segn. fault in some
situations (resetIdComponent was accidentally called twice
in a couple of places :)
Platforms:
arabica (sparc-sun-solaris 2.7)
Diffstat (limited to 'c++/src/H5Exception.cpp')
-rw-r--r-- | c++/src/H5Exception.cpp | 92 |
1 files changed, 61 insertions, 31 deletions
diff --git a/c++/src/H5Exception.cpp b/c++/src/H5Exception.cpp index 86606db..3eeb2b8 100644 --- a/c++/src/H5Exception.cpp +++ b/c++/src/H5Exception.cpp @@ -6,33 +6,43 @@ #include "H5Include.h" #include <string> - -// Added this line for CC to work at this time. Will remove it when -// the problem is fixed. BMR - 10/30/00 - #include "H5Exception.h" #ifndef H5_NO_NAMESPACE namespace H5 { #endif -Exception::Exception() : detailMessage("") {} +// Default constructor +Exception::Exception() : detailMessage(""), funcName("") {} + +// Constructor taking only a detailed message as string object +//Exception::Exception(const string& message) : detailMessage(message) {} +// Constructor taking a function name and a detailed message as string objects +Exception::Exception(const string& func_name, const string& message) : detailMessage(message), funcName(func_name) {} + +// Constructor taking a detailed message as character string // digital alpha (gondolin) produces compilation error at static_cast<string> // so I replaced this constructor by the one below it //Exception::Exception( const char* message) : detailMessage(static_cast<string>(message)) {} - -Exception::Exception( const char* message) +//Exception::Exception(const char* message) +//{ + //detailMessage = string(message); +//} + +// Constructor taking a function name and a detailed message as character +// strings +Exception::Exception(const char* func_name, const char* message) { - detailMessage = string( message ); + detailMessage = string(message); + funcName = string(func_name); } -Exception::Exception( const string& message ) : detailMessage( message ) {} - // copy constructor Exception::Exception( const Exception& orig ) { detailMessage = orig.detailMessage; + funcName = orig.funcName; } // Returns the character string that describes an error specified by @@ -62,7 +72,7 @@ void Exception::setAutoPrint( H5E_auto_t func, void* client_data ) // the specified function. herr_t ret_value = H5Eset_auto( func, client_data ); if( ret_value < 0 ) - throw Exception( "Exception::setAutoPrint" ); + throw Exception( "Exception::setAutoPrint", "H5Eset_auto failed" ); } // Turns off the automatic error printing. @@ -72,7 +82,7 @@ void Exception::dontPrint() // off the automatic error printing. herr_t ret_value = H5Eset_auto( NULL, NULL ); if( ret_value < 0 ) - throw Exception( "Exception::dontPrint" ); + throw Exception( "Exception::dontPrint", "H5Eset_auto failed" ); } // Retrieves the current settings for the automatic error stack traversal @@ -83,7 +93,7 @@ void Exception::getAutoPrint( H5E_auto_t& func, void** client_data ) // the automatic error printing herr_t ret_value = H5Eget_auto( &func, client_data ); if( ret_value < 0 ) - throw Exception( "Exception::getAutoPrint" ); + throw Exception( "Exception::getAutoPrint", "H5Eget_auto failed" ); } // Clears the error stack for the current thread. @@ -92,7 +102,7 @@ void Exception::clearErrorStack() // calls the C API routine H5Eclear to clear the error stack herr_t ret_value = H5Eclear(); if( ret_value < 0 ) - throw Exception( "Exception::clearErrorStack" ); + throw Exception( "Exception::clearErrorStack", "H5Eclear failed" ); } // Walks the error stack for the current thread, calling the specified function. @@ -101,7 +111,7 @@ void Exception::walkErrorStack( H5E_direction_t direction, H5E_walk_t func, void // calls the C API routine H5Ewalk to walk the error stack herr_t ret_value = H5Ewalk( direction, func, client_data ); if( ret_value < 0 ) - throw Exception( "Exception::walkErrorStack" ); + throw Exception( "Exception::walkErrorStack", "H5Ewalk failed" ); } // Default error stack traversal callback function that prints error @@ -111,18 +121,28 @@ void Exception::walkDefErrorStack( int n, H5E_error_t& err_desc, void* client_da // calls the C API routine H5Ewalk_cb to walk the error stack herr_t ret_value = H5Ewalk_cb( n, &err_desc, client_data ); if( ret_value < 0 ) - throw Exception( "Exception::walkDefErrorStack" ); + throw Exception( "Exception::walkDefErrorStack", "H5Ewalk_cb failed" ); } // Returns the detailed message set at the time the exception is thrown -string Exception::getDetailMesg() const +string Exception::getDetailMsg() const { - return( detailMessage ); + return(detailMessage); } -const char* Exception::getCDetailMesg() const +const char* Exception::getCDetailMsg() const +{ + return(detailMessage.c_str()); +} + +// Returns the function name where the exception is thrown +string Exception::getFuncName() const +{ + return(funcName); +} +const char* Exception::getCFuncName() const { - return( detailMessage.c_str() ); + return(funcName.c_str()); } // Prints the error stack in a default manner. @@ -130,49 +150,59 @@ void Exception::printError( FILE* stream ) const { herr_t ret_value = H5Eprint( NULL ); // print to stderr if( ret_value < 0 ) - throw Exception( "Exception::printError" ); + throw Exception( "Exception::printError", "H5Eprint failed" ); } Exception::~Exception() {} FileIException::FileIException():Exception(){} -FileIException::FileIException( string message ): Exception( message ){} +FileIException::FileIException(const string& func_name, const string& message) : Exception(func_name, message) {} +FileIException::FileIException(const char* func_name, const char* message) : Exception(func_name, message) {} FileIException::~FileIException() {} GroupIException::GroupIException():Exception(){} -GroupIException::GroupIException( string message ): Exception( message ){} +GroupIException::GroupIException(const string& func_name, const string& message) : Exception(func_name, message) {} +GroupIException::GroupIException(const char* func_name, const char* message) : Exception(func_name, message) {} GroupIException::~GroupIException() {} DataSpaceIException::DataSpaceIException():Exception(){} -DataSpaceIException::DataSpaceIException( string message ): Exception( message ) {} +DataSpaceIException::DataSpaceIException(const string& func_name, const string& message) : Exception(func_name, message) {} +DataSpaceIException::DataSpaceIException(const char* func_name, const char* message) : Exception(func_name, message) {} DataSpaceIException::~DataSpaceIException() {} DataTypeIException::DataTypeIException():Exception(){} -DataTypeIException::DataTypeIException( string message ): Exception( message ) {} +DataTypeIException::DataTypeIException(const string& func_name, const string& message) : Exception(func_name, message) {} +DataTypeIException::DataTypeIException(const char* func_name, const char* message) : Exception(func_name, message) {} DataTypeIException::~DataTypeIException() {} PropListIException::PropListIException():Exception(){} -PropListIException::PropListIException( string message ): Exception( message ) {} +PropListIException::PropListIException(const string& func_name, const string& message) : Exception(func_name, message) {} +PropListIException::PropListIException(const char* func_name, const char* message) : Exception(func_name, message) {} PropListIException::~PropListIException() {} DataSetIException::DataSetIException():Exception(){} -DataSetIException::DataSetIException( string message ): Exception( message ) {} +DataSetIException::DataSetIException(const string& func_name, const string& message) : Exception(func_name, message) {} +DataSetIException::DataSetIException(const char* func_name, const char* message) : Exception(func_name, message) {} DataSetIException::~DataSetIException() {} AttributeIException::AttributeIException():Exception(){} -AttributeIException::AttributeIException( string message ): Exception( message ) {} +AttributeIException::AttributeIException(const string& func_name, const string& message) : Exception(func_name, message) {} +AttributeIException::AttributeIException(const char* func_name, const char* message) : Exception(func_name, message) {} AttributeIException::~AttributeIException() {} ReferenceException::ReferenceException():Exception(){} -ReferenceException::ReferenceException( string message ): Exception( message ) {} +ReferenceException::ReferenceException(const string& func_name, const string& message) : Exception(func_name, message) {} +ReferenceException::ReferenceException(const char* func_name, const char* message) : Exception(func_name, message) {} ReferenceException::~ReferenceException() {} LibraryIException::LibraryIException():Exception(){} -LibraryIException::LibraryIException( string message ): Exception( message ) {} +LibraryIException::LibraryIException(const string& func_name, const string& message) : Exception(func_name, message) {} +LibraryIException::LibraryIException(const char* func_name, const char* message) : Exception(func_name, message) {} LibraryIException::~LibraryIException() {} IdComponentException::IdComponentException(): Exception() {} -IdComponentException::IdComponentException( string message ): Exception( message ) {} +IdComponentException::IdComponentException(const string& func_name, const string& message) : Exception(func_name, message) {} +IdComponentException::IdComponentException(const char* func_name, const char* message) : Exception(func_name, message) {} IdComponentException::~IdComponentException() {} // The following are from Java API but not done here: |