-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.h
90 lines (79 loc) · 2.83 KB
/
exceptions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef EXCEPTIONS_H_INCLUDED
#define EXCEPTIONS_H_INCLUDED
#include <exception>
#include <sstream>
#include "str.h"
#include "strutil.h"
class BetterException : std::exception {
public:
virtual std::string message() = 0;
};
struct FileNotFoundException : BetterException {
const char* filePath;
FileNotFoundException(const char* filePath) : filePath(filePath) {}
std::string message() override {
std::ostringstream output;
output << "File " << filePath << " not found.";
return output.str();
}
};
struct IndexOutOfBoundsException : BetterException {
int index, bound;
IndexOutOfBoundsException(int index, int bound) : index(index), bound(bound) {}
std::string message() override {
std::ostringstream output;
output << "Index " << index << " out of bounds [0, " << bound << "].";
return output.str();
}
};
struct NoCharInStrException : BetterException {
char ch;
const Str& str;
NoCharInStrException(char ch, const Str& str) : ch(ch), str(str) {}
std::string message() override {
std::ostringstream output;
StrUtil::printChar(output << "No ", ch) << " in ";
StrUtil::sample(str, 4, output);
return output.str();
}
};
struct ReadIllegalQualLenException : BetterException {
const Str& ident;
unsigned seqLen, qualLen;
ReadIllegalQualLenException(const Str& ident, unsigned seqLen, unsigned qualLen) :
ident(ident), seqLen(seqLen), qualLen(qualLen) {}
std::string message() override {
std::ostringstream output;
output << "Read has different sequence length (" << seqLen << ") and quality length (" << qualLen <<
") in read " << ident << ".";
return output.str();
}
};
struct ReadIllegalDefException : BetterException {
unsigned line;
ReadIllegalDefException(unsigned line) : line(line) {}
std::string message() override {
std::ostringstream output;
output << "Illegal read definition on line " << line << ".";
return output.str();
}
};
struct SeedInvalidException : BetterException {
unsigned length, interval;
SeedInvalidException(unsigned length, unsigned interval) : length(length), interval(interval) {}
std::string message() override {
std::ostringstream output;
output << "Seed length (" << length << ") smaller than seed interval (" << interval << ").";
return output.str();
}
};
struct WindowInvalidException : BetterException {
float windowReadRatio;
WindowInvalidException(float windowReadRatio) : windowReadRatio(windowReadRatio) {}
std::string message() override {
std::ostringstream output;
output << "Window:Read ratio (" << windowReadRatio << ") must be positive (preferred at least 0.5).";
return output.str();
}
};
#endif // EXCEPTIONS_H_INCLUDED