faif
ExceptionsFaif.hpp
1 #ifndef FAIF_EXCEPTIONS_H_
2 #define FAIF_EXCEPTIONS_H_
3 
4 // the base exception class for faif library
5 
6 #if defined(_MSC_VER)
7 // msvc warning 'std::copy deprecated'
8 #pragma warning(disable:4996)
9 #endif
10 
11 #include <exception>
12 #include <iostream>
13 #include <cstring>
14 
15 namespace faif {
16 
17  /** \brief the base exception class for faif library */
18  class FaifException : public std::exception {
19  public:
20  FaifException(){}
21  virtual ~FaifException() throw() {}
22  virtual const char *what() const throw() { return "FaifException"; }
23 
24  /** \brief the exception info written to ostream */
25  virtual std::ostream& print(std::ostream& os) const throw() {
26  os << what() << std::endl;
27  return os;
28  }
29  };
30 
31  /** \brief the exception thrown when the value for given attribute is not found */
33  static const int SIZE = 30;
34  public:
35  NotFoundException(const char* domain_id) {
36  strncpy(domainID_,domain_id,SIZE);
37  domainID_[SIZE-1]='\0';
38  }
39  virtual ~NotFoundException() throw() {}
40  virtual const char *what() const throw(){ return "NotFoundException"; }
41  virtual std::ostream& print(std::ostream& os) const throw() {
42  os << "Value in domain " << domainID_ << " not found";
43  return os;
44  }
45  private:
46  // the std::string is not used
47  char domainID_[SIZE];
48  };
49 
50  //the global function called ex.print(os)
51  inline std::ostream& operator<<(std::ostream& os, const FaifException& ex) {
52  ex.print(os);
53  return os;
54  }
55 
56 
57 } //namespace faif
58 
59 #endif //FAIF_EXCEPTIONS_H_
Definition: Chain.h:17
the base exception class for faif library
Definition: ExceptionsFaif.hpp:18
virtual std::ostream & print(std::ostream &os) const
the exception info written to ostream
Definition: ExceptionsFaif.hpp:41
virtual std::ostream & print(std::ostream &os) const
the exception info written to ostream
Definition: ExceptionsFaif.hpp:25
the exception thrown when the value for given attribute is not found
Definition: ExceptionsFaif.hpp:32