blitz: Catch uncaught exceptions

This commit is contained in:
Michael Fabian 'Xaymar' Dirks
2019-01-17 16:55:56 +01:00
parent 88f8f50e00
commit 7f5d100e51
+34 -13
View File
@@ -136,6 +136,7 @@ static void demoError() {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
try {
string in_file, out_file, args; string in_file, out_file, args;
@@ -149,28 +150,38 @@ int main(int argc, char *argv[]) {
if (t == "-h") { if (t == "-h") {
showhelp = true; showhelp = true;
} else if (t == "-a") { }
else if (t == "-a") {
dumpasm = true; dumpasm = true;
} else if (t == "-q") { }
else if (t == "-q") {
quiet = true; quiet = true;
} else if (t == "+q") { }
else if (t == "+q") {
quiet = veryquiet = true; quiet = veryquiet = true;
} else if (t == "-c") { }
else if (t == "-c") {
compileonly = true; compileonly = true;
} else if (t == "-d") { }
else if (t == "-d") {
debug = true; debug = true;
} else if (t == "-k") { }
else if (t == "-k") {
dumpkeys = true; dumpkeys = true;
} else if (t == "+k") { }
else if (t == "+k") {
dumpkeys = dumphelp = true; dumpkeys = dumphelp = true;
} else if (t == "-v") { }
else if (t == "-v") {
versinfo = true; versinfo = true;
} else if (t == "-o") { }
else if (t == "-o") {
if (out_file.size() || k == argc - 1) if (out_file.size() || k == argc - 1)
usageErr(); usageErr();
out_file = argv[++k]; out_file = argv[++k];
} else { }
else {
if (in_file.size() || t[0] == '-' || t[0] == '+') if (in_file.size() || t[0] == '-' || t[0] == '+')
usageErr(); usageErr();
@@ -201,7 +212,7 @@ int main(int argc, char *argv[]) {
if (in_file[0] == '\"') { if (in_file[0] == '\"') {
if ((in_file.size() < 3) || (in_file[in_file.size() - 1] != '\"')) { if ((in_file.size() < 3) || (in_file[in_file.size() - 1] != '\"')) {
usageErr(); usageErr();
} }
in_file = in_file.substr(1, in_file.size() - 2); in_file = in_file.substr(1, in_file.size() - 2);
} }
@@ -252,7 +263,8 @@ int main(int argc, char *argv[]) {
Assem_x86 assem(asmcode, module); Assem_x86 assem(asmcode, module);
assem.assemble(); assem.assemble();
} catch (Ex &x) { }
catch (Ex &x) {
string file = '\"' + x.file + '\"'; string file = '\"' + x.file + '\"';
int row = ((x.pos >> 16) & 65535) + 1, col = (x.pos & 65535) + 1; int row = ((x.pos >> 16) & 65535) + 1, col = (x.pos & 65535) + 1;
@@ -267,7 +279,8 @@ int main(int argc, char *argv[]) {
if (!module->createExe(out_file.c_str(), (home + "/bin/runtime.dll").c_str())) { if (!module->createExe(out_file.c_str(), (home + "/bin/runtime.dll").c_str())) {
err("Error creating executable"); err("Error creating executable");
} }
} else if (!compileonly) { }
else if (!compileonly) {
void *entry = module->link(runtimeModule); void *entry = module->link(runtimeModule);
if (!entry) return 0; if (!entry) return 0;
@@ -297,4 +310,12 @@ int main(int argc, char *argv[]) {
closeLibs(); closeLibs();
return 0; return 0;
}
catch (std::exception& e) {
std::cout << "Unexpected exception: " << e.what() << std::endl;
}
catch (...) {
std::cout << "Unexpected error." << std::endl;
}
} }