-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
put exception handling/conversion in a utility routine
- Loading branch information
1 parent
819a99d
commit ea1c03e
Showing
4 changed files
with
108 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* ========================================================================= | ||
* This file is part of hd5.lite-c++ | ||
* ========================================================================= | ||
* | ||
* (C) Copyright 2022, Maxar Technologies, Inc. | ||
* | ||
* hd5.lite-c++ is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; If not, | ||
* see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "hdf5.lite.h" | ||
|
||
void hdf5::lite::details::try_catch_H5Exceptions(std::function<void(void*)> f, void* context) | ||
{ | ||
try | ||
{ | ||
/* | ||
* Turn off the auto-printing when failure occurs so that we can | ||
* handle the errors appropriately | ||
*/ | ||
H5::Exception::dontPrint(); | ||
|
||
f(context); | ||
} | ||
// catch failure caused by the H5File operations | ||
catch (const H5::FileIException& error) | ||
{ | ||
const except::Context ctx(error.getDetailMsg(), __FILE__, __LINE__, error.getFuncName()); | ||
throw except::IOException(ctx); | ||
} | ||
// catch failure caused by the DataSet operations | ||
catch (const H5::DataSetIException& error) | ||
{ | ||
const except::Context ctx(error.getDetailMsg(), __FILE__, __LINE__, error.getFuncName()); | ||
throw hdf5::lite::DataSetException11(ctx); | ||
} | ||
// catch failure caused by the DataSpace operations | ||
catch (const H5::DataSpaceIException& error) | ||
{ | ||
const except::Context ctx(error.getDetailMsg(), __FILE__, __LINE__, error.getFuncName()); | ||
throw hdf5::lite::DataSpaceException11(ctx); | ||
} | ||
// catch failure caused by the DataType operations | ||
catch (const H5::DataTypeIException& error) | ||
{ | ||
const except::Context ctx(error.getDetailMsg(), __FILE__, __LINE__, error.getFuncName()); | ||
throw hdf5::lite::DataTypeException11(ctx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* ========================================================================= | ||
* This file is part of hd5.lite-c++ | ||
* ========================================================================= | ||
* | ||
* (C) Copyright 2022, Maxar Technologies, Inc. | ||
* | ||
* hd5.lite-c++ is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; If not, | ||
* see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <functional> | ||
#include <stdexcept> | ||
|
||
// see https://docs.hdfgroup.org/archive/support/HDF5/doc1.8/cpplus_RM/readdata_8cpp-example.html | ||
#include <H5Cpp.h> | ||
|
||
#include "except/Exception.h" | ||
#include "hdf5/lite/HDF5Exception.h" | ||
|
||
// Utility routines for INTERNAL use! | ||
|
||
namespace hdf5 | ||
{ | ||
namespace lite | ||
{ | ||
namespace details | ||
{ | ||
void try_catch_H5Exceptions(std::function<void(void*)> f, void* context = nullptr); | ||
} | ||
} | ||
} |