-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathInvalidArgumentException.h
48 lines (43 loc) · 1.63 KB
/
InvalidArgumentException.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
#pragma once
#include <exception>
#include <stdexcept>
#include <string>
#include <sstream>
namespace CppForCsExceptions {
class InvalidArgumentExceptionBase : public std::invalid_argument {
public:
InvalidArgumentExceptionBase(void) : std::invalid_argument("") { }
virtual ~InvalidArgumentExceptionBase(void) throw() { }
virtual const char* what(void) const throw() override = 0;
};
template <class T>
class InvalidArgumentException : public InvalidArgumentExceptionBase {
public:
inline InvalidArgumentException(const char* className,
const char* functionSignature,
const char* parameterName,
T parameterValue);
inline virtual ~InvalidArgumentException(void) throw();
inline virtual const char* what(void) const throw() override;
private:
std::string m_whatMessage;
};
template<class T>
InvalidArgumentException<T>::InvalidArgumentException(
const char* className,
const char* functionSignature,
const char* parameterName,
T parameterValue) : InvalidArgumentExceptionBase(), m_whatMessage() {
std::stringstream msg;
msg << className << "::" << functionSignature
<< " - parameter '" << parameterName
<< "' had invalid value '" << parameterValue << "'.";
m_whatMessage = std::string(msg.str());
}
template<class T>
InvalidArgumentException<T>::~InvalidArgumentException(void) throw() {}
template<class T>
const char* InvalidArgumentException<T>::what(void) const throw() {
return m_whatMessage.c_str();
}
}