Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef PARSEREXCEPTIONS_H_
00009 #define PARSEREXCEPTIONS_H_
00010
00011 #include <sstream>
00012 #include <iostream>
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include <errno.h>
00016
00017 using namespace std;
00018
00019 class ParserException{
00020 protected:
00021 int _line;
00022 int _position;
00023
00024 ParserException(std::string desc="", int line = 0, int position = 0)
00025 : desc(desc), _line(line), _position(position) { };
00026 virtual ~ParserException(){};
00027 std::string desc;
00028 public:
00029 std::string what() const {
00030 stringstream ss;
00031 ss << desc;
00032
00033 if (_line > 0 && _position > 0)
00034 ss << endl << "Line: " << _line << ", position: " << _position;
00035
00036 return ss.str();
00037 }
00038
00039 template <class A>
00040 ParserException& operator<<(const A& a){
00041 std::stringstream s;
00042 s<<a;
00043 desc += s.str();
00044 return *this;
00045 }
00046 };
00047
00048 class UnexpectedEndOfFile : public ParserException {
00049 public:
00050 UnexpectedEndOfFile(string expectedString = "", int line = 0, int position = 0)
00051 : ParserException("Expected string '" + expectedString + "' not found", line, position) { }
00052 };
00053
00054 class ClosingBracketNotFound : public ParserException {
00055 public:
00056 ClosingBracketNotFound() : ParserException("Closing bracket not found") { }
00057 };
00058
00059 class UnexpectedToken: public ParserException {
00060 public:
00061 UnexpectedToken(string character, string expectedToken = "", int line = 0, int position = 0)
00062 : ParserException("Unexpected character: '" + character + "', expected: '" + expectedToken + "'", line, position) { }
00063 };
00064
00065 class PEFileNotFound:public ParserException{
00066 public:
00067 PEFileNotFound(std::string filename):ParserException("File "+filename+" does not found. ")
00068 {
00069 (*this)<<"\n\tIOError: "<<strerror( errno );
00070 }
00071 };
00072
00073 class PEFileNotCreated:public ParserException{
00074 public:
00075 PEFileNotCreated(std::string filename):ParserException("File "+filename+" cann't be open. ")
00076 {
00077 (*this)<<"\n\tIOError: "<<strerror( errno );
00078 }
00079 };
00080
00081 #endif