From 0c39051ba80f04b1177833a006f2d442a7170b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 3 Dec 2020 17:11:43 +0100 Subject: add initial files l8 --- labb8/lib/StanfordCPPLib/main.cpp | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100755 labb8/lib/StanfordCPPLib/main.cpp (limited to 'labb8/lib/StanfordCPPLib/main.cpp') diff --git a/labb8/lib/StanfordCPPLib/main.cpp b/labb8/lib/StanfordCPPLib/main.cpp new file mode 100755 index 0000000..6feb8aa --- /dev/null +++ b/labb8/lib/StanfordCPPLib/main.cpp @@ -0,0 +1,108 @@ +/* + * File: main.cpp + * -------------- + * This file defines a default version of the Main function that takes + * the argc and argv arguments. This function must be defined in its + * own module to ensure that it is loaded only if the client doesn't + * supply one. + */ + +#include +#include +#include + +using namespace std; + +int Main(int, char *[]) { + extern int Main(); + return Main(); +} + +void __StanfordCPPLib_terminate_handler() { + try { + throw; // re-throws the exception that already occurred + } 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"; + cerr << 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"; + cerr << 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"; + cerr << 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"; + cerr << 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"; + cerr << 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"; + cerr << 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"; + cerr << 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"; + cerr << msg; + throw d; + } + abort(); +} + +void __StanfordCPPLib_set_terminate() { + set_terminate(__StanfordCPPLib_terminate_handler); +} -- cgit v1.2.1