Collage  1.4.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 ) : _type( type ) {}
45 
47  virtual ~Exception() throw() {}
48 
50  virtual uint32_t getType() const { return _type; }
51 
53  const char* what() const throw() override
54  {
55  switch( _type )
56  {
58  return " Timeout on write operation";
60  return " Timeout on read operation";
61  default:
62  return " Unknown Exception";
63  }
64  }
65 
66  private:
68  const uint32_t _type;
69  };
70 
72  inline std::ostream& operator << ( std::ostream& os, const Exception& e )
73  { return os << e.what(); }
74 }
75 
76 #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:50
A read timeout operation.
Definition: exception.h:39
virtual ~Exception()
Destruct this exception.
Definition: exception.h:47
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:53
Type
The exception type.
Definition: exception.h:36