summaryrefslogtreecommitdiff
path: root/src/exception.cpp
blob: 1a7958c7b6fc927c82e8684dae757101d172a51e (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
52
#include <exception.h>
#include <exceptions.h>
#include <config.h>
#include <cerrno>
#include <cstring>
#include <utils.h>
#include <strprintf.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 type::ATTRIB_UNAVAIL:
		errmsg = strprintf::fmt(_("attribute `%s' is not available."), addinfo);
		break;
	case type::INVALID_REGEX:
		errmsg = strprintf::fmt(_("regular expression '%s' is invalid: %s"), addinfo, addinfo2);
		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 action_handler_status::INVALID_PARAMS:
		return _("invalid parameters.");
	case action_handler_status::TOO_FEW_PARAMS:
		return _("too few parameters.");
	case action_handler_status::INVALID_COMMAND:
		return _("unknown command (bug).");
	case action_handler_status::FILENOTFOUND:
		return _("file couldn't be opened.");
	default:
		return _("unknown error (bug).");
	}
}

}