/
bioExceptions.h
52 lines (43 loc) · 1.38 KB
/
bioExceptions.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
//-*-c++-*------------------------------------------------------------
//
// File name : bioExceptions.h
// @date Fri Apr 13 09:03:41 2018
// @author Michel Bierlaire
// @version Revision 1.0
//
//--------------------------------------------------------------------
#ifndef bioExceptions_h
#define bioExceptions_h
#include <stdexcept>
#include <sstream>
#include <exception>
#include "bioString.h"
// Prepares the messages for the exceptions
class bioExceptions: public std::runtime_error {
public:
bioExceptions(bioString f, int l, bioString m) throw() : std::runtime_error(m) {
std::stringstream str ;
str << f << ":" << l << ": Biogeme exception: " << m ;
msg = str.str() ;
}
virtual ~bioExceptions() throw() {}
const char *what() const throw() {
return msg.c_str();
}
private:
bioString msg ;
};
class bioExceptNullPointer: public bioExceptions {
public:
bioExceptNullPointer(bioString f, int l, bioString ptr) throw() : bioExceptions(f,l,"Null pointer: "+ptr) {
}
virtual ~bioExceptNullPointer() throw() {}
};
template <class T> class bioExceptOutOfRange: public bioExceptions {
bioString msg ;
public:
bioExceptOutOfRange(bioString f, int l, T v, T lb, T ub) throw() : bioExceptions(f,l,"Value "+ std::to_string(v) + " out of range [" + std::to_string(lb) + "," + std::to_string(ub) + "]") {
}
virtual ~bioExceptOutOfRange() throw() {}
};
#endif