Skip to content

Commit

Permalink
throw loos errors on h5 open exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
agrossfield committed Mar 29, 2024
1 parent f2191ba commit 9ffd6b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/mdtraj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ namespace loos {
// turn off printed exceptions
//H5::Exception::dontPrint();
// Open the hdf5 file
H5::H5File file(_filename, H5F_ACC_RDONLY);
H5::H5File file;
try {
file.openFile(_filename, H5F_ACC_RDONLY);
}
catch(H5::FileIException& e) {
throw(FileOpenError(_filename));
}

// Retrieve the topology from the HDF5 file
std::string topology_json = getTopology(file);
Expand Down
7 changes: 6 additions & 1 deletion src/mdtrajtraj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ namespace loos {

// Scan the trajectory file to determine frame sizes and box
void MDTrajTraj::init(void) {
file.openFile(_filename, H5F_ACC_RDONLY);
try {
file.openFile(_filename, H5F_ACC_RDONLY);
}
catch(H5::FileIException& e) {
throw(FileOpenError(_filename));
}

hsize_t box_dims[3];
if (H5Lexists(file.getId(), "cell_lengths", H5P_DEFAULT)) {
Expand Down

0 comments on commit 9ffd6b4

Please sign in to comment.