summaryrefslogtreecommitdiffstats
path: root/labb8/lib/StanfordCPPLib/startup.cpp
blob: d6d3ff83eee8d127dbfdda146a94d91bc237a33f (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
/*
 * File: startup.cpp
 * -----------------
 * This file implements the wrapper for main that allows for
 * system initialization and error handling.
 */

#include <cstdlib>
#include <iostream>
#include "error.h"
using namespace std;

#if defined (_MSC_VER) && (_MSC_VER >= 1200)
#  include <windows.h>
#  define MSC_ERROR_FLAGS (MB_OK | MB_ICONSTOP | MB_TOPMOST)
#endif

/* Global flag word indicating option for main */

int _mainFlags;

int mainWrapper(int argc, char **argv) {
   extern int Main(int argc, char **argv);
   try {
      return Main(argc, argv);
   } catch (ErrorException & ex) {
      string msg = "Error: " + ex.getMessage();
      cerr << msg << endl;
#ifdef _MSC_VER
      MessageBoxA(NULL, msg.c_str(), "Error!", MSC_ERROR_FLAGS);
#endif
      return EXIT_FAILURE;
   }
}