ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UtilsExceptions.h
Go to the documentation of this file.
1 
11 #ifndef UTILSEXECPT_H_
12 #define UTILSEXECPT_H_
13 
14 #include<string>
15 #include<stdexcept>
16 #include<iostream>
17 
18 // missing message here ?
19 
25 // can use public virtual std::exception for avoiding diamond problem, read about limitation
26 // it seems can work only from std::exception (not runtime_exception because no virtual public
27 class FileError : public std::exception
28 {
29  public:
30  // define constructor without argument, maybe copy, assignement is needed
31  // should not, by reference always
32  /*
33  FileError() : std::exception() {
34 #ifdef DEBUG_EXCEPT
35  std::cout << "Constructor FileError without argument" << std::endl;
36 #endif
37  }
38  */
39  FileError( const std::string& fileIn) : std::exception(), mFile( fileIn ), mFileMsg("") {
40 #ifdef DEBUG_EXCEPT
41  std::cout << "Contructor Base FileError with one argument filename " << std::endl;
42 #endif
43  }
44  FileError( const std::string& fileIn, const std::string(msg) ) : std::exception(), mFile( fileIn ),mFileMsg(msg) {}
45  // needed with g++ 4.6, no need with 4.7
46  // indicates than nothing is throw, normal for destructor, to check !!
47  ~FileError() throw() {}
50  virtual const char * what() const noexcept {
51  return mFileMsg.c_str();
52  }
53  std::string getFileName() const { return mFile; }
54  // maybe getmMsg, but used by polymorphism
55 
56  protected:
57  std::string mFile, mFileMsg;
58 };
59 
61 class FileOpenError : public FileError
62 {
63  public:
64  FileOpenError( const std::string& fileNameIn);
65 };
66 
68 class FileEmptyError : public FileError
69 {
70  public:
71  FileEmptyError( const std::string & fileNameIn );
72 };
73 
75 class FileReadError : public FileError
76 {
77  public:
78  FileReadError(const std::string& fileNameIn, int lineNumIn = -1 );
79  FileReadError(const std::string& fileNameIn, const std::string& msg );
80  int getLineNum() { return mLineNum; }
81 
82  // specific data member, optional, give the line number
83  protected:
84  int mLineNum;
85 };
86 
87 #endif /* UTILSEXCEPT_H */
std::string mFile
Base class for error handling with files.
Specific class when the file cannot be found and opened.
FileError(const std::string &fileIn, const std::string(msg))
virtual const char * what() const noexcept
for getting the message with standard interface do not throw exception
for dealing with error in reading, problem of formatting for instance
std::string getFileName() const
FileReadError(const std::string &fileNameIn, int lineNumIn=-1)
std::string mFileMsg
FileEmptyError(const std::string &fileNameIn)
if empty eally or empty of data
FileError(const std::string &fileIn)
add my own, if file is empty really or empty of data
FileOpenError(const std::string &fileNameIn)
Modify the message do make it explicit.