Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/508 for code review #554

Merged
merged 7 commits into from
Jul 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2014-07-24 Ivan Gonzalez <iglpdc@gmail.com>

* lib/khmer.hh, lib/khmer_exception.hh: All exceptions are now derived from
a new base class exception, khmer::khmer_exception. Issue #508.
* lib/counting.cc, lib/hashbits.cc, lib/hashtable.{cc,hh},lib/kmer_hash.cc,
lib/labelhash.cc, lib/perf_metrics.hh, lib/read_parsers.{cc,hh},
lib/subset.cc, lib/thread_id_map.hh: All exceptions thrown are now
instances (or derived from) khmer::khmer_exception.

2014-07-22 Jeramia Ory <jeramia.ory@gmail.com>

* khmer/_khmermodule.cc: removed unused KhmerError, issue #503
Expand Down
8 changes: 4 additions & 4 deletions lib/counting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ CountingHash::abundance_distribution(
// if not, could lead to overflow.
if (sizeof(BoundedCounterType) != 2) {
delete[] dist;
throw std::exception();
throw khmer_exception();
}

while(!parser->is_complete()) {
Expand Down Expand Up @@ -282,7 +282,7 @@ void CountingHash::get_kadian_count(
}

if (!counts.size()) {
throw std::exception();
throw khmer_exception();
}
unsigned int kpos = nk * _ksize;

Expand Down Expand Up @@ -658,7 +658,7 @@ CountingHashFileWriter::CountingHashFileWriter(
const CountingHash &ht)
{
if (!ht._counts[0]) {
throw std::exception();
throw khmer_exception();
}

unsigned int save_ksize = ht._ksize;
Expand Down Expand Up @@ -711,7 +711,7 @@ CountingHashGzFileWriter::CountingHashGzFileWriter(
const CountingHash &ht)
{
if (!ht._counts[0]) {
throw std::exception();
throw khmer_exception();
}

unsigned int save_ksize = ht._ksize;
Expand Down
2 changes: 1 addition & 1 deletion lib/hashbits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace khmer:: read_parsers;
void Hashbits::save(std::string outfilename)
{
if (!_counts[0]) {
throw std::exception();
throw khmer_exception();
}

unsigned int save_ksize = _ksize;
Expand Down
10 changes: 5 additions & 5 deletions lib/hashtable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void Hashtable::get_median_count(const std::string &s,
}

if (!counts.size()) {
throw std::exception();
throw khmer_exception();
}

if (!counts.size()) {
Expand Down Expand Up @@ -1159,7 +1159,7 @@ const
}

if (!(breadth >= cur_breadth)) { // keep track of watermark, for debugging.
throw std::exception();
throw khmer_exception();
}
if (breadth > cur_breadth) {
cur_breadth = breadth;
Expand Down Expand Up @@ -1524,7 +1524,7 @@ const
}

if (!(breadth >= cur_breadth)) { // keep track of watermark, for debugging.
throw std::exception();
throw khmer_exception();
}
if (breadth > cur_breadth) {
cur_breadth = breadth;
Expand Down Expand Up @@ -1729,7 +1729,7 @@ const
}

if (!(breadth >= cur_breadth)) { // keep track of watermark, for debugging.
throw std::exception();
throw khmer_exception();
}
if (breadth > cur_breadth) {
cur_breadth = breadth;
Expand Down Expand Up @@ -2036,7 +2036,7 @@ void Hashtable::extract_unique_paths(std::string seq,
// then extract.

if (!(j == min_length)) {
throw std::exception();
throw khmer_exception();
}
if ( ((float)seen_counter / (float) j) <= max_seen) {
unsigned int start = i;
Expand Down
10 changes: 5 additions & 5 deletions lib/hashtable.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <vector>
#include <iostream>
#include <exception>
#include <list>
#include <queue>

Expand All @@ -21,6 +20,7 @@
#include <queue>

#include "khmer.hh"
#include "khmer_exception.hh"
#include "read_parsers.hh"
#include "subset.hh"
#include "kmer_hash.hh"
Expand Down Expand Up @@ -109,7 +109,7 @@ public:

HashIntoType next(HashIntoType& f, HashIntoType& r) {
if (done()) {
throw std::exception();
throw khmer_exception();
}

if (!initialized) {
Expand All @@ -120,7 +120,7 @@ public:
unsigned char ch = _seq[index];
index++;
if (!(index <= length)) {
throw std::exception();
throw khmer_exception();
}

// left-shift the previous hash over
Expand Down Expand Up @@ -211,7 +211,7 @@ protected:
_ksize( ksize ) {
_tag_density = DEFAULT_TAG_DENSITY;
if (!(_tag_density % 2 == 0)) {
throw std::exception();
throw khmer_exception();
}
partition = new SubsetPartition(this);
_init_bitstuff();
Expand Down Expand Up @@ -398,7 +398,7 @@ public:
// for debugging/testing purposes only!
void _set_tag_density(unsigned int d) {
if (!(d % 2 == 0) || !all_tags.empty()) { // must be even and tags must exist
throw std::exception();
throw khmer_exception();
}
_tag_density = d;
}
Expand Down
36 changes: 2 additions & 34 deletions lib/khmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ __attribute__((cpychecker_type_object_for_typedef(typename)))
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(typename)
#endif

// C++ standard exceptions are subclassed almost ubiquitously.
#include <exception>
#include <set>
#include <map>
#include <queue>

#include "khmer_exception.hh"

# define MAX_COUNT 255
# define MAX_BIGCOUNT 65535
# define DEFAULT_TAG_DENSITY 40 // must be even
Expand Down Expand Up @@ -80,10 +80,6 @@ typedef void (*CallbackFn)(const char * info, void * callback_data,
unsigned long long n_reads,
unsigned long long other);

struct InvalidStreamBuffer : public std:: exception {
};


typedef unsigned int PartitionID;
typedef std::set<HashIntoType> SeenSet;
typedef std::set<PartitionID> PartitionSet;
Expand Down Expand Up @@ -116,34 +112,6 @@ void deallocate_ptr_set(T& s)
}
}

class khmer_file_exception : public std::exception
{
public:
khmer_file_exception(const char * msg) : _msg(msg) { };

virtual const char* what() const throw() {
return _msg;
}
protected:
const char * _msg;
};

class InvalidStreamHandle : public khmer_file_exception
{
public:
InvalidStreamHandle()
: khmer_file_exception("Generic InvalidStreamHandle error") {}
InvalidStreamHandle(const char * msg) : khmer_file_exception(msg) {}
};

class StreamReadError : public khmer_file_exception
{
public:
StreamReadError()
: khmer_file_exception("Generic StreamReadError error") {}
StreamReadError(const char * msg) : khmer_file_exception(msg) {}
};

}

#endif // KHMER_HH
70 changes: 70 additions & 0 deletions lib/khmer_exception.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// This file is part of khmer, http://github.com/ged-lab/khmer/, and is
// Copyright (C) Michigan State University, 2009-2013. It is licensed under
// the three-clause BSD license; see doc/LICENSE.txt.
// Contact: khmer-project@idyll.org
//

#ifndef KHMER_EXCEPTION_HH
#define KHMER_EXCEPTION_HH

#include <exception>
#include <string>

namespace khmer
{

///
// A base class for all exceptions.
//
// All exceptions should be derived from this base class.
//
class khmer_exception : public std::exception
{
public:
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; }

protected:
const char * _msg;
};

///
// A base class for file exceptions.
//
class khmer_file_exception : public khmer_exception
{
public:
explicit khmer_file_exception(const char * msg) : khmer_exception(msg) { }
explicit khmer_file_exception(const std::string& msg)
: khmer_exception(msg) { }
};

struct InvalidStreamBuffer : public khmer_exception {
};

class InvalidStreamHandle : public khmer_file_exception
{
public:
InvalidStreamHandle()
: khmer_file_exception("Generic InvalidStreamHandle error") {}
InvalidStreamHandle(const char * msg) : khmer_file_exception(msg) {}
};

class StreamReadError : public khmer_file_exception
{
public:
StreamReadError()
: khmer_file_exception("Generic StreamReadError error") {}
StreamReadError(const char * msg) : khmer_file_exception(msg) {}
};

}

#endif // KHMER_EXCEPTION_HH

// vim: set sts=2 sw=2:
2 changes: 1 addition & 1 deletion lib/kmer_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ HashIntoType _hash(const char * kmer, const WordLength k,
{
// sizeof(HashIntoType) * 8 bits / 2 bits/base
if (!(k <= sizeof(HashIntoType)*4) || !(strlen(kmer) >= k)) {
throw std::exception();
throw khmer_exception();
}

HashIntoType h = 0, r = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/labelhash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ unsigned int LabelHash::sweep_label_neighborhood(const std::string& seq,
//printf("range=%u ", range);
if (range == 0) {
if (!(num_traversed == seq.length()-ksize()+1)) {
throw std::exception();
throw khmer_exception();
}
}
tagged_kmers.clear();
Expand Down
4 changes: 1 addition & 3 deletions lib/perf_metrics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
#include <cstring>
#include <ctime>

#include <exception>

#include "khmer.hh"


namespace khmer
{

#ifdef WITH_INTERNAL_METRICS
struct InvalidPerformanceMetricsKey : public std:: exception {
struct InvalidPerformanceMetricsKey : public khmer_exception {
};


Expand Down
6 changes: 3 additions & 3 deletions lib/read_parsers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1411,23 +1411,23 @@ IParser(
REG_EXTENDED | REG_NOSUB
);
if (regex_rc) {
throw std::exception();
throw khmer_exception();
}
regex_rc =
regcomp(
&_re_read_1,
"^.+(/1| 1:[YN]:[[:digit:]]+:[[:alpha:]]+).{0}", REG_EXTENDED
);
if (regex_rc) {
throw std::exception();
throw khmer_exception();
}
regex_rc =
regcomp(
&_re_read_2,
"^.+(/2| 2:[YN]:[[:digit:]]+:[[:alpha:]]+).{0}", REG_EXTENDED
);
if (regex_rc) {
throw std::exception();
throw khmer_exception();
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/read_parsers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading