Collage  1.1.2
High-performance C++ library for developing object-oriented distributed applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
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 
24 #include <exception> // base class
25 #include <iostream>
26 #include <lunchbox/compiler.h>
27 #include <lunchbox/types.h>
28 
29 namespace co
30 {
32  class Exception : public std::exception
33  {
34  public:
36  enum Type
37  {
42  CUSTOM = 20
43  };
44 
46  explicit Exception( const uint32_t type ) : _type( type ) {}
47 
49  virtual ~Exception() throw() {}
50 
52  virtual uint32_t getType() const { return _type; }
53 
55  const char* what() const throw() override
56  {
57  switch( _type )
58  {
60  return " Timeout on write operation";
62  return " Timeout on read operation";
64  return " Timeout on barrier";
66  return " Timeout on command queue";
67  default:
68  return " Unknown Exception";
69  }
70  }
71 
72  private:
74  const uint32_t _type;
75  };
76 
78  inline std::ostream& operator << ( std::ostream& os, const Exception& e )
79  { return os << e.what(); }
80 }
81 
82 #endif // CO_EXCEPTION_H
A base Exception class for Collage operations.
Definition: exception.h:32
A timeout on a cmd queue operation.
Definition: exception.h:41
Application-specific exceptions.
Definition: exception.h:42
A barrier timeout operation.
Definition: exception.h:40
A write timeout operation.
Definition: exception.h:38
virtual uint32_t getType() const
Definition: exception.h:52
A read timeout operation.
Definition: exception.h:39
virtual ~Exception()
Destruct this exception.
Definition: exception.h:49
Exception(const uint32_t type)
Construct a new Exception.
Definition: exception.h:46
const char * what() const override
Output the exception in human-readable form.
Definition: exception.h:55
Type
The exception type.
Definition: exception.h:36