1 /*
2 	SObjectizer 5.
3 */
4 
5 /*!
6 	\file
7 	\brief An exception class.
8 */
9 
10 #pragma once
11 
12 #include <stdexcept>
13 #include <string>
14 
15 #include <so_5/declspec.hpp>
16 #include <so_5/compiler_features.hpp>
17 #include <so_5/ret_code.hpp>
18 
19 namespace so_5
20 {
21 
22 #if defined( SO_5_MSVC )
23 	#pragma warning(push)
24 	#pragma warning(disable: 4275)
25 #endif
26 
27 //
28 // exception_t
29 //
30 
31 //! The base class for all SObjectizer exceptions.
32 class SO_5_TYPE exception_t : public std::runtime_error
33 {
34 	public:
exception_t(const std::string & error_descr,int error_code)35 		exception_t(
36 			const std::string & error_descr,
37 			int error_code )
38 			:	std::runtime_error( error_descr )
39 			,	m_error_code( error_code )
40 			{}
41 		exception_t( const exception_t & ) = default;
42 		exception_t( exception_t && ) = default;
43 
44 		exception_t &
45 		operator=( exception_t & o ) = default;
46 
47 		exception_t &
48 		operator=( exception_t && o ) = default;
49 
50 		//! Error code getter.
51 		int
error_code() const52 		error_code() const noexcept { return m_error_code; }
53 
54 		static void
55 		raise(
56 			const char * file_name,
57 			unsigned int line_number,
58 			const std::string & error_descr,
59 			int error_code );
60 
61 	private:
62 		//! Error code.
63 		int m_error_code;
64 };
65 
66 #if defined( SO_5_MSVC )
67 	#pragma warning(pop)
68 #endif
69 
70 #define SO_5_THROW_EXCEPTION_IMPL(file, line, error_code, desc)\
71 	so_5::exception_t::raise(file, line, (desc), (error_code))
72 
73 #define SO_5_THROW_EXCEPTION(error_code, desc)\
74 	SO_5_THROW_EXCEPTION_IMPL(__FILE__, __LINE__, error_code, desc)
75 
76 } /* namespace so_5 */
77 
78