hpp-util  4.9.0
Debugging tools for the HPP project.
exception.hh
Go to the documentation of this file.
1 // Copyright (C) 2010 by Thomas Moulard, CNRS.
2 //
3 // This file is part of the hpp-util.
4 //
5 // This software is provided "as is" without warranty of any kind,
6 // either expressed or implied, including but not limited to the
7 // implied warranties of fitness for a particular purpose.
8 //
9 // See the COPYING file for more information.
10 
12 
13 #ifndef HPP_UTIL_EXCEPTION_HH
14 # define HPP_UTIL_EXCEPTION_HH
15 # include <iosfwd>
16 # include <stdexcept>
17 # include <string>
18 
19 # include <hpp/util/config.hh>
20 
21 namespace hpp
22 {
26  class HPP_UTIL_DLLAPI Exception : public std::exception
27  {
28  public:
29  Exception (const std::string& message,
30  const std::string& file,
31  unsigned line) throw ();
32  ~Exception () throw ();
33  Exception (const Exception& exception) throw ();
34  Exception& operator= (const Exception& exception) throw ();
35 
36  virtual const char* what () const throw ();
37 
42  virtual std::ostream& print (std::ostream& o) const throw ();
43  private:
44  std::string message_;
45  std::string file_;
46  unsigned line_;
47  };
48 
54  HPP_UTIL_DLLAPI std::ostream&
55  operator<< (std::ostream& o, const Exception& exception);
56 
57 } // end of namespace hpp.
58 
60 # define HPP_THROW_EXCEPTION_(MSG) \
61  throw ::hpp::Exception (MSG, __FILE__, __LINE__)
62 
64 # define HPP_THROW_EXCEPTION(TYPE, MSG) \
65  throw TYPE (MSG, __FILE__, __LINE__)
66 
68 # define HPP_MAKE_EXCEPTION(EXTRA_QUALIFIER, TYPE) \
69  class EXTRA_QUALIFIER TYPE : public ::hpp::Exception \
70  { \
71  public: \
72  TYPE (const std::string& message, \
73  const std::string& file, \
74  unsigned line) throw () \
75  : ::hpp::Exception (message, file, line) \
76  {} \
77  }
78 
80 # define HPP_MAKE_EXCEPTION_NO_QUALIFIER(TYPE) \
81  class TYPE : public ::hpp::Exception \
82  { \
83  public: \
84  TYPE (const std::string& message, \
85  const std::string& file, \
86  unsigned line) throw () \
87  : ::hpp::Exception (message, file, line) \
88  {} \
89  }
90 
91 #endif
Definition: assertion.hh:24
HPP_UTIL_DLLAPI std::ostream & operator<<(std::ostream &o, const Exception &exception)
Override operator<< to handle exception display.
Definition: exception.cc:75
Main exception class for HPP.
Definition: exception.hh:26