Voxel
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
exception.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef EXCEPTION_H
4 #define EXCEPTION_H
5 
6 
7 /**
8  \file
9  \brief Contains Exception class.
10 */
11 
12 
13 
14 
15 #include <string>
16 #include <stdexcept>
17 
18 
19 
20 
21 /*==============================================================================
22  THROW_EXCEPTION macros
23 ==============================================================================*/
24 
25 
26 /// \brief Throws an Exception labeled with the file, line and string \p what.
27 #define THROW_EXCEPTION( what ) \
28  throw ::Exception( __FILE__, __LINE__, ( what ) )
29 
30 /// \brief Throws an Exception labeled with the file, line, and strings \p what and \p message. Typically, \p what will describe the failure, and \p message will be a library error message.
31 #define THROW_EXCEPTION_MESSAGE( what, message ) \
32  throw ::Exception( __FILE__, __LINE__, ( what ), ( message ) )
33 
34 
35 
36 
37 /*==============================================================================
38  Exception class
39 ==============================================================================*/
40 
41 
42 /**
43  \brief Default exception class.
44 
45  Exceptions should not be constructed explicitly. Instead, use the
46  THROW_EXCEPTION() and THROW_EXCEPTION_MESSAGE() macros, which will
47  construct and throw exceptions annotated with the filename and line number
48  of the failure.
49 
50  The error message returned by what() has the following components:
51 
52  1. Filename and line number at which the exception was thrown.
53  2. Description string \p what passed to the constructor.
54  3. (Optional) string \p message passed to the constructor, intended to be used to store error messages from external libraries (although the WindowsException and OpenCL::Exception classes handle this for \c HRESULT error codes and OpenCL error codes, respectively).
55 */
56 struct Exception : public std::exception {
57 
58  Exception( char const* const file, unsigned int const line, std::string const& what );
59  Exception( char const* const file, unsigned int const line, std::string const& what, char const* const message );
60 
61 
62  virtual ~Exception() throw();
63 
64 
65  virtual const char* what() const throw(); ///< Returns text (UTF-8) error message for this exception.
66 
67 
68 private:
69 
70  std::string m_what;
71 };
72 
73 
74 
75 
76 #endif // EXCEPTION_H