blob: c55564c4079f66a2a866ff5427926f1856aaaf68 (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* File: console.cpp
* -----------------
* This file implements the console.h interface.
*/
#include <string>
#include "console.h"
#include "error.h"
#include "platform.h"
using namespace std;
static void sclTerminateHandler();
static Platform *pp = getPlatform();
static bool consoleEcho = false;
static bool consolePrintExceptions = false;
static string consoleLogFile = "";
static void (*old_terminate)() = NULL;
void clearConsole() {
pp->clearConsole();
}
bool getConsoleEcho() {
return consoleEcho;
}
string getConsoleLogFile() {
return consoleLogFile;
}
bool getConsolePrintExceptions() {
return consolePrintExceptions;
}
void setConsoleEcho(bool echo) {
consoleEcho = echo;
}
void setConsoleFont(const string & font) {
pp->setConsoleFont(font);
}
void setConsoleLogFile(const string & filename) {
consoleLogFile = filename;
}
void setConsolePrintExceptions(bool printExceptions) {
if (printExceptions && !consolePrintExceptions) {
old_terminate = set_terminate(sclTerminateHandler);
} else if (!printExceptions && consolePrintExceptions) {
set_terminate(old_terminate);
}
consolePrintExceptions = printExceptions;
}
void setConsoleSize(double width, double height) {
pp->setConsoleSize(width, height);
}
static void sclTerminateHandler() {
ostream& out = cerr;
try {
throw; // re-throws the exception that already occurred
} catch (const ErrorException& ex) {
string msg = "\n ***\n";
msg += " *** STANFORD C++ LIBRARY \n";
msg += " *** An ErrorException occurred during program execution: \n";
msg += " *** ";
msg += ex.what();
msg += "\n ***\n\n";
cout.flush();
out << msg;
throw ex;
} catch (const std::exception& ex) {
string msg = "\n ***\n";
msg += " *** STANFORD C++ LIBRARY \n";
msg += " *** An exception occurred during program execution: \n";
msg += " *** ";
msg += ex.what();
msg += "\n ***\n\n";
cout.flush();
out << msg;
throw ex;
} catch (std::string str) {
string msg = "\n ***\n";
msg += " *** STANFORD C++ LIBRARY \n";
msg += " *** A string exception occurred during program execution: \n";
msg += " *** \"";
msg += str;
msg += "\"\n ***\n";
cout.flush();
out << msg;
throw str;
} catch (char const* str) {
string msg = "\n ***\n";
msg += " *** STANFORD C++ LIBRARY \n";
msg += " *** A string exception occurred during program execution: \n";
msg += " *** \"";
msg += str;
msg += "\"\n ***\n";
cout.flush();
out << msg;
throw str;
} catch (int n) {
char buf[128];
snprintf(buf, 128, "%d", n);
string msg = "\n ***\n";
msg += " *** STANFORD C++ LIBRARY \n";
msg += " *** An int exception occurred during program execution: \n";
msg += " *** ";
msg += buf;
msg += "\n ***\n\n";
cout.flush();
out << msg;
throw n;
} catch (long l) {
char buf[128];
snprintf(buf, 128, "%ld", l);
string msg = "\n ***\n";
msg += " *** STANFORD C++ LIBRARY \n";
msg += " *** A long exception occurred during program execution: \n";
msg += " *** ";
msg += buf;
msg += "\n ***\n\n";
cout.flush();
out << msg;
throw l;
} catch (char c) {
string msg = "\n ***\n";
msg += " *** STANFORD C++ LIBRARY \n";
msg += " *** A char exception occurred during program execution: \n";
msg += " *** '";
msg += c;
msg += "'\n ***\n";
cout.flush();
out << msg;
throw c;
} catch (bool b) {
string msg = "\n ***\n";
msg += " *** STANFORD C++ LIBRARY \n";
msg += " *** A bool exception occurred during program execution: \n";
msg += " *** ";
msg += (b ? "true" : "false");
msg += "\n ***\n\n";
cout.flush();
out << msg;
throw b;
} catch (double d) {
char buf[128];
snprintf(buf, 128, "%lf", d);
string msg = "\n ***\n";
msg += " *** STANFORD C++ LIBRARY \n";
msg += " *** A double exception occurred during program execution: \n";
msg += " *** ";
msg += buf;
msg += "\n ***\n\n";
cout.flush();
out << msg;
throw d;
}
abort();
}
|