summaryrefslogtreecommitdiff
path: root/src/exception.cpp
blob: 112d923c8cb9bca4a0235fc5449d8ff2b29e4d7c (plain) (blame)
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
#include <exception.h>
#include <exceptions.h>
#include <config.h>
#include <cerrno>
#include <cstring>
#include <utils.h>

namespace newsbeuter {

exception::exception(unsigned int error_code) : ecode(error_code) { }

exception::~exception() throw() { }

const char * exception::what() const throw() {
	return ::strerror(ecode);
}


const char * matcherexception::what() const throw() {
	static std::string errmsg;
	switch (type) {
	case ATTRIB_UNAVAIL:
		errmsg = utils::strprintf(_("attribute `%s' is not available."), addinfo.c_str());
		break;
	case INVALID_REGEX:
		errmsg = utils::strprintf(_("regular expression '%s' is invalid: %s"), addinfo.c_str(), addinfo2.c_str());
		break;
	}
	return errmsg.c_str();
}

confighandlerexception::confighandlerexception(action_handler_status e) {
	msg = get_errmsg(e);
}

const char * confighandlerexception::get_errmsg(action_handler_status status) {
	switch (status) {
	case AHS_INVALID_PARAMS:
		return _("invalid parameters.");
	case AHS_TOO_FEW_PARAMS:
		return _("too few parameters.");
	case AHS_INVALID_COMMAND:
		return _("unknown command (bug).");
	case AHS_FILENOTFOUND:
		return _("file couldn't be opened.");
	default:
		return _("unknown error (bug).");
	}
}

}