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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
#include "stdafx.h"
#include "Exception.h"
#include "StrBuf.h"
namespace storm {
Exception::Exception() : stackTrace(engine()) {}
Exception::Exception(const Exception &o) : stackTrace(o.stackTrace) {}
void Exception::deepCopy(CloneEnv *env) {}
Str *Exception::message() const {
StrBuf *b = new (this) StrBuf();
message(b);
return b->toS();
}
void Exception::toS(StrBuf *to) const {
message(to);
if (stackTrace.any()) {
*to << S("\n");
stackTrace.format(to);
}
}
Exception *Exception::saveTrace() {
if (stackTrace.empty()) {
try {
stackTrace = collectStackTrace(engine());
} catch (...) {
// If we get an error, we just ignore it here. Better that we can throw an exception
// at all than crashing when trying to grab a stack trace!
}
}
return this;
}
Exception *Exception::saveTrace(void *context) {
if (stackTrace.empty()) {
try {
stackTrace = collectStackTrace(engine(), context);
} catch (...) {
// If we get an error, we just ignore it here. Better that we can throw an exception
// at all than crashing when trying to grab a stack trace!
}
}
return this;
}
MultiException::MultiException() {
exceptions = new (this) Array<Exception *>();
}
MultiException::MultiException(Array<Exception *> *exceptions) : exceptions(exceptions) {}
void MultiException::push(Exception *exception) {
exceptions->push(exception);
}
void MultiException::message(StrBuf *to) const {
*to << S("Collection of ") << exceptions->count();
if (exceptions->count() == 1)
*to << S(" exception:");
else
*to << S(" exceptions:");
to->indent();
for (Nat i = 0; i < exceptions->count(); i++) {
*to << S("\n") << exceptions->at(i);
}
to->dedent();
}
RuntimeError::RuntimeError() {}
GcError::GcError(const wchar *msg) : msg(msg) {
saveTrace();
}
void GcError::message(StrBuf *to) const {
*to << S("GC error: ") << msg;
}
NumericError::NumericError() {}
DivisionByZero::DivisionByZero() {
saveTrace();
}
DivisionByZero::DivisionByZero(void *context) {
saveTrace(context);
}
void DivisionByZero::message(StrBuf *to) const {
*to << S("Integer division by zero");
}
MemoryAccessError::MemoryAccessError(Word address, Type type) : address(address), type(type) {
saveTrace();
}
MemoryAccessError::MemoryAccessError(Word address, Type type, void *context) : address(address), type(type) {
saveTrace(context);
}
void MemoryAccessError::message(StrBuf *to) const {
*to << S("Memory access error: ");
switch (type) {
case notMapped:
*to << S("address 0x") << hex(size_t(address)) << S(" is not valid.");
break;
case invalidAccess:
*to << S("access to address 0x") << hex(size_t(address)) << S(" does not match memory permissions.");
break;
case invalidAlignment:
*to << S("address 0x") << hex(size_t(address)) << S(" is not properly aligned.");
break;
case kernel:
*to << S("address 0x") << hex(size_t(address)) << S(" is reserved by the kernel (reported address might be incorrect).");
break;
}
}
NotSupported::NotSupported(const wchar *msg) {
this->msg = new (this) Str(msg);
saveTrace();
}
NotSupported::NotSupported(Str *msg) {
this->msg = msg;
saveTrace();
}
void NotSupported::message(StrBuf *to) const {
*to << S("Operation not supported: ") << msg;
}
UsageError::UsageError(const wchar *msg) {
this->msg = new (this) Str(msg);
saveTrace();
}
UsageError::UsageError(Str *msg) : msg(msg) {
saveTrace();
}
void UsageError::message(StrBuf *to) const {
*to << msg;
}
InternalError::InternalError(const wchar *msg) {
this->msg = new (this) Str(msg);
saveTrace();
}
InternalError::InternalError(Str *msg) {
this->msg = msg;
saveTrace();
}
void InternalError::message(StrBuf *to) const {
*to << S("Internal error: ") << msg;
}
AbstractFnCalled::AbstractFnCalled(const wchar *name) : RuntimeError() {
this->name = new (this) Str(name);
}
AbstractFnCalled::AbstractFnCalled(Str *name) : RuntimeError(), name(name) {}
void AbstractFnCalled::message(StrBuf *to) const {
*to << S("Abstract function called: ") << name;
}
StrError::StrError(const wchar *msg) {
this->msg = new (this) Str(msg);
saveTrace();
}
StrError::StrError(Str *msg) {
this->msg = msg;
saveTrace();
}
void StrError::message(StrBuf *to) const {
*to << msg;
}
MapError::MapError(const wchar *msg) {
this->msg = new (this) Str(msg);
saveTrace();
}
MapError::MapError(Str *msg) {
this->msg = msg;
saveTrace();
}
void MapError::message(StrBuf *to) const {
*to << S("Map error: ") << msg;
}
SetError::SetError(const wchar *msg) {
this->msg = new (this) Str(msg);
saveTrace();
}
SetError::SetError(Str *msg) {
this->msg = msg;
saveTrace();
}
void SetError::message(StrBuf *to) const {
*to << S("Set error: ") << msg;
}
ArrayError::ArrayError(Nat id, Nat count) : id(id), count(count), msg(null) {
saveTrace();
}
ArrayError::ArrayError(Nat id, Nat count, Str *msg) : id(id), count(count), msg(msg) {
saveTrace();
}
void ArrayError::message(StrBuf *to) const {
*to << S("Array error: Index ") << id << S(" out of bounds (of ") << count << S(").");
if (msg)
*to << S(" During ") << msg << S(".");
}
}
|