diff --git a/include/ndhist/Exceptions.hh b/include/ndhist/Exceptions.hh new file mode 100644 index 0000000..ec953ca --- /dev/null +++ b/include/ndhist/Exceptions.hh @@ -0,0 +1,23 @@ +#ifndef NDHIST_EXCEPTIONS +#define NDHIST_EXCEPTIONS + +#include +#include + +// exceptions +class HistogramSaveError: public std::runtime_error { +public: + HistogramSaveError(const std::string&); +}; + +class HistogramBinningError: public std::logic_error { +public: + HistogramBinningError(const std::string&); +}; + +class HistogramNanError: public HistogramBinningError { +public: + HistogramNanError(const std::string&); +}; + +#endif diff --git a/include/ndhist/Histogram.hh b/include/ndhist/Histogram.hh index c2b3926..18f2543 100644 --- a/include/ndhist/Histogram.hh +++ b/include/ndhist/Histogram.hh @@ -27,7 +27,6 @@ #include #include #include -#include namespace H5 { class CommonFG; @@ -103,11 +102,6 @@ private: std::string m_wt2_ext; }; -// exceptions -class HistogramSaveError: public std::runtime_error { -public: - HistogramSaveError(const std::string&); -}; // global swap void swap(Histogram&, Histogram&); diff --git a/makefile b/makefile index 0cb3306..63a5d4d 100644 --- a/makefile +++ b/makefile @@ -40,7 +40,7 @@ LIBS += -lhdf5_cpp -lhdf5 # ---- define objects # - not-python -GEN_OBJ := Histogram.o Binners.o h5tools.o Distribution.o +GEN_OBJ := Histogram.o Binners.o h5tools.o Distribution.o Exceptions.o # - command line interface EXE_OBJ := test.o diff --git a/src/Binners.cxx b/src/Binners.cxx index 93243ea..2e43a37 100644 --- a/src/Binners.cxx +++ b/src/Binners.cxx @@ -1,5 +1,5 @@ #include "Binners.hh" -#include +#include "Exceptions.hh" #include #include @@ -56,7 +56,8 @@ int LinBinner::get_bin(const std::map& locator) const typedef std::map DMap; DMap::const_iterator bin_itr = locator.find(m_name); if (bin_itr == locator.end()) { - throw std::runtime_error("could not find " + m_name + " in values given"); + throw HistogramBinningError( + "could not find " + m_name + " in values given"); } double value = bin_itr->second; int bin = get_bin(value); @@ -73,7 +74,8 @@ int LinBinner::get_bin(const std::vector& locator, size_t offset) { int index = locator.size() - offset - 1; if (index < 0) { - throw std::runtime_error("could not find " + m_name + " in values given"); + throw HistogramBinningError( + "could not find " + m_name + " in values given"); } double value = locator.at(index); int bin = get_bin(value); @@ -88,7 +90,7 @@ int LinBinner::get_bin(const std::vector& locator, size_t offset) int LinBinner::get_bin(double value) const { if (std::isnan(value)) { - throw std::range_error(m_name + " binner was passed NaN"); + throw HistogramNanError(m_name + " binner was passed NaN"); } int bin = 0; if (value < m_low) { diff --git a/src/Exceptions.cxx b/src/Exceptions.cxx new file mode 100644 index 0000000..3a4ed15 --- /dev/null +++ b/src/Exceptions.cxx @@ -0,0 +1,16 @@ +#include "Exceptions.hh" + +//______________________________________________________________________ +// exception definitions + +HistogramSaveError::HistogramSaveError(const std::string& what): + std::runtime_error(what) +{} + +HistogramBinningError::HistogramBinningError(const std::string& what): + std::logic_error(what) +{} + +HistogramNanError::HistogramNanError(const std::string& what): + HistogramBinningError(what) +{} diff --git a/src/Histogram.cxx b/src/Histogram.cxx index 8cafa2b..03a3e94 100644 --- a/src/Histogram.cxx +++ b/src/Histogram.cxx @@ -3,8 +3,8 @@ #include "h5tools.hh" #include "Binners.hh" +#include "Exceptions.hh" -#include #include #include #include @@ -318,12 +318,6 @@ namespace { } -//______________________________________________________________________ -// exception definitions - -HistogramSaveError::HistogramSaveError(const std::string& what): - std::runtime_error(what) -{} // ____________________________________________________________________ // swap diff --git a/src/test.cxx b/src/test.cxx index 0353422..b166368 100644 --- a/src/test.cxx +++ b/src/test.cxx @@ -1,6 +1,7 @@ #include "Histogram.hh" #include "Binners.hh" #include "Distribution.hh" +#include "Exceptions.hh" #include "H5Cpp.h" #include