From 92135e8032e499167dec6098c663f7ebb0b0b499 Mon Sep 17 00:00:00 2001 From: Ivan Gonzalez Date: Tue, 22 Jul 2014 21:40:17 +0200 Subject: [PATCH] All exceptions defined in khmer are derived class from khmer::khmer_exception, including khmer::khmer_file_exception. --- lib/khmer.hh | 4 ++-- lib/khmer_exception.hh | 18 +++++++++++++----- lib/perf_metrics.hh | 4 +--- lib/read_parsers.hh | 12 ++++++------ lib/thread_id_map.hh | 5 ++--- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/khmer.hh b/lib/khmer.hh index 612b93240e..93f856cda9 100644 --- a/lib/khmer.hh +++ b/lib/khmer.hh @@ -58,7 +58,7 @@ __attribute__((cpychecker_type_object_for_typedef(typename))) # define MIN( a, b ) (((a) > (b)) ? (b) : (a)) # define MAX( a, b ) (((a) < (b)) ? (b) : (a)) -#include +#include "khmer_exception.hh" namespace khmer { // largest number we can count up to, exactly. (8 bytes) @@ -79,7 +79,7 @@ typedef void (*CallbackFn)(const char * info, void * callback_data, unsigned long long n_reads, unsigned long long other); -struct InvalidStreamBuffer : public std:: exception { +struct InvalidStreamBuffer : public khmer_exception { }; diff --git a/lib/khmer_exception.hh b/lib/khmer_exception.hh index 7ecedc9838..741e3babc5 100644 --- a/lib/khmer_exception.hh +++ b/lib/khmer_exception.hh @@ -9,6 +9,7 @@ #define KHMER_EXCEPTION_HH #include +#include namespace khmer { @@ -21,19 +22,26 @@ namespace khmer class khmer_exception : public std::exception { public: - khmer_exception(const char * msg) : _msg(msg) { }; + explicit khmer_exception(const char * msg) : _msg(msg) { } + explicit khmer_exception(const std::string& msg = "Generic khmer exception") + : _msg(msg.c_str()) { } + + virtual ~khmer_exception() throw() { } + virtual const char* what() const throw () { return _msg; } - virtual const char* what() const throw() { - return _msg; - } protected: const char * _msg; }; +/// +// A base class for file exceptions. +// class khmer_file_exception : public khmer_exception { public: - khmer_file_exception(const char * msg) : khmer_exception(msg) { }; + explicit khmer_file_exception(const char * msg) : khmer_exception(msg) { } + explicit khmer_file_exception(const std::string& msg) + : khmer_exception(msg) { } }; } diff --git a/lib/perf_metrics.hh b/lib/perf_metrics.hh index c4a377b9a1..aecd21d879 100644 --- a/lib/perf_metrics.hh +++ b/lib/perf_metrics.hh @@ -12,16 +12,14 @@ #include #include -#include #include "khmer.hh" - namespace khmer { #ifdef WITH_INTERNAL_METRICS -struct InvalidPerformanceMetricsKey : public std:: exception { +struct InvalidPerformanceMetricsKey : public khmer_exception { }; diff --git a/lib/read_parsers.hh b/lib/read_parsers.hh index cba6bef8da..6668c87e7f 100644 --- a/lib/read_parsers.hh +++ b/lib/read_parsers.hh @@ -84,22 +84,22 @@ public: }; -struct CacheSegmentUnavailable : public std:: exception { +struct CacheSegmentUnavailable : public khmer_exception { }; -struct CacheSegmentBoundaryViolation : public std:: exception { +struct CacheSegmentBoundaryViolation : public khmer_exception { }; -struct InvalidCacheSizeRequested : public std:: exception { +struct InvalidCacheSizeRequested : public khmer_exception { }; -struct NoMoreReadsAvailable : public std:: exception { +struct NoMoreReadsAvailable : public khmer_exception { }; -struct UnknownPairReadingMode : public std:: exception { +struct UnknownPairReadingMode : public khmer_exception { }; -struct InvalidReadPair : public std:: exception { +struct InvalidReadPair : public khmer_exception { }; #ifdef WITH_INTERNAL_METRICS diff --git a/lib/thread_id_map.hh b/lib/thread_id_map.hh index b1e718d95a..4d3d7f3124 100644 --- a/lib/thread_id_map.hh +++ b/lib/thread_id_map.hh @@ -8,7 +8,6 @@ #ifndef THREAD_ID_MAP_HH # define THREAD_ID_MAP_HH -#include #include // TODO? Just use 'pthread_t' everywhere. @@ -31,10 +30,10 @@ namespace khmer { -struct InvalidNumberOfThreadsRequested : public std:: exception { +struct InvalidNumberOfThreadsRequested : public khmer_exception { }; -struct TooManyThreads : public std:: exception { +struct TooManyThreads : public khmer_exception { };