Line data Source code
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 : {
31 : /** A base Exception class for Collage operations. */
32 : class Exception : public std::exception
33 : {
34 : public:
35 : /** The exception type. @version 1.0 */
36 : enum Type
37 : {
38 : TIMEOUT_WRITE, //!< A write timeout operation
39 : TIMEOUT_READ, //!< A read timeout operation
40 : CUSTOM = 20 //!< Application-specific exceptions
41 : };
42 :
43 : /** Construct a new Exception. @version 1.0 */
44 0 : explicit Exception(const uint32_t type)
45 0 : : _type(type)
46 : {
47 0 : }
48 :
49 : /** Destruct this exception. @version 1.0 */
50 0 : virtual ~Exception() throw() {}
51 : /** @return the type of this exception @version 1.0 */
52 0 : virtual uint32_t getType() const { return _type; }
53 : /** Output the exception in human-readable form. @version 1.0 */
54 0 : const char* what() const throw() override
55 : {
56 0 : switch (_type)
57 : {
58 : case Exception::TIMEOUT_WRITE:
59 0 : return " Timeout on write operation";
60 : case Exception::TIMEOUT_READ:
61 0 : return " Timeout on read operation";
62 : default:
63 0 : return " Unknown Exception";
64 : }
65 : }
66 :
67 : private:
68 : /** The type of this eception instance **/
69 : const uint32_t _type;
70 : };
71 :
72 : /** Output the exception in human-readable form. @version 1.0 */
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
|