00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "errorhandler.hpp"
00011 #include <iostream>
00012 #include <fstream>
00013
00014 using namespace std;
00015
00016 int ErrorHandler::TotalErrors = 0;
00017
00019
00024 void ErrorHandler::error ( int lineNumber, const string &message)
00025 {
00026 cerr << lineNumber << ": " << message << endl;
00027
00028 ++TotalErrors;
00029
00030
00031 if (TotalErrors == 10)
00032 {
00033 cerr << endl << "Maximum errors exceeded, bailing out" << endl << endl;
00034 exit(-1);
00035 }
00036 }
00037
00039
00046 void ErrorHandler::error (const string &file, const int &line, const int &column, const string &msg)
00047 {
00048 char buf[80];
00049 ifstream fp(file.c_str());
00050
00051
00052 for (int i = 0; i < line; i++)
00053 {
00054 fp.getline (buf, 80);
00055 }
00056
00057 cerr << msg << " at line " << line << endl;
00058
00059
00060 cerr << buf << endl;
00061
00062
00063 for (int i = 0; i < column - 1; i++)
00064 {
00065 cerr << ' ';
00066 }
00067 cerr << "^ error" << endl << endl;
00068
00069 fp.close();
00070 }