-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_manager.h
48 lines (40 loc) · 1.18 KB
/
error_manager.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.h"
#include "utils.h"
class ErrorManager
{
public:
virtual ~ErrorManager() {
}
protected:
bool fatal_error = false;
pfc::array_t<pfc::string8> errors;
void add_error(const char* msg, bool fatal = false) {
fatal_error = fatal_error || fatal;
pfc::string8 error;
error << (fatal ? "(FATAL) " : "(skipped) ") << "Error: " << msg;
errors.append_single(error);
}
void add_error(foo_discogs_exception &e, bool fatal = false) {
fatal_error = fatal_error || fatal;
pfc::string8 error;
error << (fatal ? "(FATAL) " : "(skipped) ") << "Error: " << e.what();
errors.append_single(error);
}
void add_error(const char* msg, foo_discogs_exception &e, bool fatal = false) {
fatal_error = fatal_error || fatal;
pfc::string8 error;
error << (fatal ? "(FATAL) " : "(skipped) ") << "Error [" << msg << "]: " << e.what();
errors.append_single(error);
}
// displays errors in popup
void display_errors() {
if (errors.get_count()) {
errors.append_single(pfc::string8("\n[ESCAPE to close]"));
popup_message::g_show(join(errors, "\n").get_ptr(), "Error(s)", popup_message::icon_error);
}
}
void clear_errors() {
errors.force_reset();
}
};