summaryrefslogtreecommitdiffstats
path: root/c++/src/H5File.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2001-03-10 03:59:46 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2001-03-10 03:59:46 (GMT)
commit9cd9f7f5216fbc30b10426f5bd11e26d81668eac (patch)
treebe3e4f25e5a870f8e98c7b1cfce3917a5dd19269 /c++/src/H5File.cpp
parentcd29e12e0252ccfc969281c5dabd991b46203f05 (diff)
downloadhdf5-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/H5File.cpp')
-rw-r--r--c++/src/H5File.cpp76
1 files changed, 46 insertions, 30 deletions
diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp
index a9058bd..9a668c4 100644
--- a/c++/src/H5File.cpp
+++ b/c++/src/H5File.cpp
@@ -38,26 +38,29 @@ H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& c
// constructors taking a string or a char*
void H5File::getFile( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist )
{
- // These bits only set for creation, so if any of them are set,
- // create the file.
- if( flags & (H5F_ACC_EXCL|H5F_ACC_TRUNC|H5F_ACC_DEBUG ))
- {
- hid_t create_plist_id = create_plist.getId();
- hid_t access_plist_id = access_plist.getId();
- id = H5Fcreate( name, flags, create_plist_id, access_plist_id );
- }
- // Open the file if none of the bits above are set.
- else
- {
- // use create_plist for access plist because of the default argument
- hid_t access_plist_id = create_plist.getId();
- id = H5Fopen( name, flags, access_plist_id );
- }
-
- if( id <= 0 ) // throw an exception when open/create fail
- {
- throw FileIException( "H5File constructor" );
- }
+ // These bits only set for creation, so if any of them are set,
+ // create the file.
+ if( flags & (H5F_ACC_EXCL|H5F_ACC_TRUNC|H5F_ACC_DEBUG ))
+ {
+ hid_t create_plist_id = create_plist.getId();
+ hid_t access_plist_id = access_plist.getId();
+ id = H5Fcreate( name, flags, create_plist_id, access_plist_id );
+ if( id <= 0 ) // throw an exception when open/create fail
+ {
+ throw FileIException("H5File constructor", "H5Fcreate failed");
+ }
+ }
+ // Open the file if none of the bits above are set.
+ else
+ {
+ // use create_plist for access plist because of the default argument
+ hid_t access_plist_id = create_plist.getId();
+ id = H5Fopen( name, flags, access_plist_id );
+ if( id <= 0 ) // throw an exception when open/create fail
+ {
+ throw FileIException("H5File constructor", "H5Fopen failed");
+ }
+ }
}
// Copy constructor: makes a copy of the original H5File object.
@@ -79,7 +82,7 @@ bool H5File::isHdf5(const char* name )
return false;
else // Raise exception when H5Fis_hdf5 returns a negative value
{
- throw FileIException( "H5File::isHdf5" );
+ throw FileIException("H5File::isHdf5", "H5Fis_hdf5 returned negative value");
}
}
@@ -95,14 +98,18 @@ void H5File::reopen()
{
// reset the identifier of this H5File - send 'this' in so that
// H5Fclose can be called appropriately
- resetIdComponent( this );
+ try {
+ resetIdComponent( this ); }
+ catch (Exception close_error) { // thrown by p_close
+ throw FileIException("H5File::reopen", close_error.getDetailMsg());
+ }
// call C routine to reopen the file - Note: not sure about this
// does id need to be closed later? which id to be the parameter?
id = H5Freopen( id );
if( id <= 0 ) // Raise exception when H5Freopen returns a neg value
{
- throw FileIException( "H5File::reopen" );
+ throw FileIException("H5File::reopen", "H5Freopen failed");
}
}
@@ -120,7 +127,7 @@ FileCreatPropList H5File::getCreatePlist() const
}
else
{
- throw FileIException( "H5File::getCreatePlist" );
+ throw FileIException("H5File::getCreatePlist", "H5Fget_create_plist failed");
}
}
@@ -138,7 +145,7 @@ FileAccPropList H5File::getAccessPlist() const
}
else // Raise an exception
{
- throw FileIException( "H5File::getAccessPlist" );
+ throw FileIException("H5File::getAccessPlist", "H5Fget_access_plist failed");
}
}
@@ -148,14 +155,19 @@ void H5File::p_close() const
herr_t ret_value = H5Fclose( id );
if( ret_value < 0 )
{
- throw FileIException( "H5File::p_close" );
+ throw FileIException(NULL, "H5Fclose failed");
}
}
-// Throw file exception
-void H5File::throwException() const
+// Throw file exception; used in CommonFG implementation so that proper
+// exception can be thrown for file or group. The func_name is a member
+// function of CommonFG and "H5File::" will be inserted to indicate the
+// function called is an implementation of H5File
+void H5File::throwException(const string& func_name, const string& msg) const
{
- throw FileIException();
+ string full_name = func_name;
+ full_name.insert(0, "H5File::");
+ throw FileIException(full_name, msg);
}
// The destructor of this instance calls IdComponent::reset to
@@ -166,7 +178,11 @@ void H5File::throwException() const
H5File::~H5File()
{
// The HDF5 file id will be closed properly
- resetIdComponent( this );
+ try {
+ resetIdComponent( this ); }
+ catch (Exception close_error) { // thrown by p_close
+ throw FileIException("H5File::~H5File", close_error.getDetailMsg());
+ }
}
#ifndef H5_NO_NAMESPACE