Collage  1.0.1
Object-Oriented C++ Network Library
exception.h
1 
2 /* Copyright (c) 2011, Cedric Stalder <cedric.stalder@gmail.com>
3  * 2012-2013, Stefan.Eilemann@epfl.ch
4  *
5  * This file is part of Collage <https://github.com/Eyescale/Collage>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 2.1 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef CO_EXCEPTION_H
22 #define CO_EXCEPTION_H
23 #include <sstream>
24 
25 namespace co
26 {
27  class Exception;
28  std::ostream& operator << ( std::ostream& os, const Exception& e );
29 
31  class Exception : public std::exception
32  {
33  public:
35  enum Type
36  {
41  CUSTOM = 20
42  };
43 
45  Exception( const uint32_t type ) : _type( type ) {}
46 
48  virtual ~Exception() throw() {}
49 
51  virtual uint32_t getType() const { return _type; }
52 
54  virtual const char* what() const throw()
55  {
56  switch( _type )
57  {
59  return " Timeout on write operation";
61  return " Timeout on read operation";
63  return " Timeout on barrier";
65  return " Timeout on command queue";
66  default:
67  return " Unknown Exception";
68  }
69  }
70 
71  private:
73  const uint32_t _type;
74  };
75 
77  inline std::ostream& operator << ( std::ostream& os, const Exception& e )
78  { return os << e.what(); }
79 }
80 
81 #endif // CO_EXCEPTION_H
virtual const char * what() const
Output the exception in human-readable form.
Definition: exception.h:54
A base Exception class for Collage operations.
Definition: exception.h:31
A read timeout operation.
Definition: exception.h:38
virtual uint32_t getType() const
Definition: exception.h:51
Application-specific exceptions.
Definition: exception.h:41
Type
The exception type.
Definition: exception.h:35
Exception(const uint32_t type)
Construct a new Exception.
Definition: exception.h:45
A timeout on a cmd queue operation.
Definition: exception.h:40
A barrier timeout operation.
Definition: exception.h:39
A write timeout operation.
Definition: exception.h:37
virtual ~Exception()
Destruct this exception.
Definition: exception.h:48