Collage  1.7.0
High-performance C++ library for developing object-oriented distributed applications.
exception.h
1 
2 /* Copyright (c) 2011-2015, Cedric Stalder <cedric.stalder@gmail.com>
3  * 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  {
40  CUSTOM = 20
41  };
42 
44  explicit Exception(const uint32_t type)
45  : _type(type)
46  {
47  }
48 
50  virtual ~Exception() throw() {}
52  virtual uint32_t getType() const { return _type; }
54  const char* what() const throw() override
55  {
56  switch (_type)
57  {
59  return " Timeout on write operation";
61  return " Timeout on read operation";
62  default:
63  return " Unknown Exception";
64  }
65  }
66 
67 private:
69  const uint32_t _type;
70 };
71 
73 inline std::ostream& operator<<(std::ostream& os, const Exception& e)
74 {
75  return os << e.what();
76 }
77 }
78 
79 #endif // CO_EXCEPTION_H
A base Exception class for Collage operations.
Definition: exception.h:32
Application-specific exceptions.
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:50
Object-oriented network library.
Definition: barrier.h:27
Exception(const uint32_t type)
Construct a new Exception.
Definition: exception.h:44
const char * what() const override
Output the exception in human-readable form.
Definition: exception.h:54
Type
The exception type.
Definition: exception.h:36