From 4bc9c6b1d233b0cf8872994ee22aae2dd0dd0ef9 Mon Sep 17 00:00:00 2001 From: yumetodo Date: Wed, 23 Mar 2016 01:30:54 +0900 Subject: [PATCH] add exception class and macro --- dxlibex/exception.hpp | 13 +++++++ dxlibex/exception/invalid_argument.hpp | 48 ++++++++++++++++++++++++++ dxlibex/exception/runtime_error.hpp | 48 ++++++++++++++++++++++++++ dxlibex/exception/sound_exception.hpp | 28 +++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 dxlibex/exception.hpp create mode 100644 dxlibex/exception/invalid_argument.hpp create mode 100644 dxlibex/exception/runtime_error.hpp create mode 100644 dxlibex/exception/sound_exception.hpp diff --git a/dxlibex/exception.hpp b/dxlibex/exception.hpp new file mode 100644 index 0000000..1658f9f --- /dev/null +++ b/dxlibex/exception.hpp @@ -0,0 +1,13 @@ +/*============================================================================= + Copyright (C) 2015-2016 DxLibEx project + https://github.com/Nagarei/DxLibEx/ + + Distributed under the Boost Software License, Version 1.0. + (See http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef DXLE_INC_EXCEPTION_HPP_ +#define DXLE_INC_EXCEPTION_HPP_ +#include "dxlibex/exception/runtime_error.hpp" +#include "dxlibex/exception/invalid_argument.hpp" +#include "dxlibex/exception/sound_exception.hpp" +#endif //DXLE_INC_EXCEPTION_HPP_ \ No newline at end of file diff --git a/dxlibex/exception/invalid_argument.hpp b/dxlibex/exception/invalid_argument.hpp new file mode 100644 index 0000000..65e426b --- /dev/null +++ b/dxlibex/exception/invalid_argument.hpp @@ -0,0 +1,48 @@ +/*============================================================================= + Copyright (C) 2015-2016 DxLibEx project + https://github.com/Nagarei/DxLibEx/ + + Distributed under the Boost Software License, Version 1.0. + (See http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef DXLE_INC_EXCEPTION_INVAID_ARGUMENT_HPP_ +#define DXLE_INC_EXCEPTION_INVAID_ARGUMENT_HPP_ +#include +#include +#include +#define DXLE_INVAID_ARGUMENT_THROW_WITH_MESSAGE( MESSAGE ) throw dxle::invalid_argument(__FILE__, __FUNCTION__, __LINE__, MESSAGE) +#define DXLE_INVAID_ARGUMENT_THROW_WITH_MESSAGE_IF( EXPR, MESSAGE ) if( EXPR ) throw dxle::invalid_argument(__FILE__, __FUNCTION__, __LINE__, #EXPR, MESSAGE) +namespace dxle { + namespace exception{ + using namespace std::literals; + class invalid_argument : public std::invalid_argument { + protected: + invalid_argument(const char* except_name, const char* sorce_name, const char* func_name, std::uint64_t line, const char* expression, const std::string& msg) + : std::invalid_argument( + "exception : "s + except_name + '\n' + + " in " + sorce_name + "\n" + + " " + func_name + "() (line." + std::to_string(line) + ")\n" + + " follow by below\n" + + " " + expression + + ((msg.empty() || msg[0] == '\0') ? "\n" : "\n MESSAGE : " + msg + "\n") + ) + {} + invalid_argument(const char* except_name, const char* sorce_name, const char* func_name, std::uint64_t line, const std::string& msg) + : std::invalid_argument( + "exception : "s + except_name + '\n' + + " in " + sorce_name + "\n" + + " " + func_name + "() (line." + std::to_string(line) + ")\n" + + ((msg.empty() || msg[0] == '\0') ? "\n" : " MESSAGE : " + msg + "\n") + ) + {} + public: + invalid_argument(const char* sorce_name, const char* func_name, std::uint64_t line, const char* expression, const std::string& msg) + : invalid_argument("invalid_argument", sorce_name, func_name, line, expression, msg) {} + invalid_argument(const char* sorce_name, const char* func_name, std::uint64_t line, const std::string& msg) + : invalid_argument("invalid_argument", sorce_name, func_name, line, msg) {} + }; + + } + using exception::invalid_argument; +} +#endif //DXLE_INC_EXCEPTION_INVAID_ARGUMENT_HPP_ \ No newline at end of file diff --git a/dxlibex/exception/runtime_error.hpp b/dxlibex/exception/runtime_error.hpp new file mode 100644 index 0000000..29b5b56 --- /dev/null +++ b/dxlibex/exception/runtime_error.hpp @@ -0,0 +1,48 @@ +/*============================================================================= + Copyright (C) 2015-2016 DxLibEx project + https://github.com/Nagarei/DxLibEx/ + + Distributed under the Boost Software License, Version 1.0. + (See http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef DXLE_INC_EXCEPTION_RUNTIME_ERROR_HPP_ +#define DXLE_INC_EXCEPTION_RUNTIME_ERROR_HPP_ +#include +#include +#include +#define DXLE_RUNTIME_ERROR_THROW_WITH_MESSAGE( MESSAGE ) throw dxle::runtime_error(__FILE__, __FUNCTION__, __LINE__, MESSAGE) +#define DXLE_RUNTIME_ERROR_THROW_WITH_MESSAGE_IF( EXPR, MESSAGE ) if( EXPR ) throw dxle::runtime_error(__FILE__, __FUNCTION__, __LINE__, #EXPR, MESSAGE) +namespace dxle { + namespace exception{ + using namespace std::literals; + class runtime_error : public std::runtime_error { + protected: + runtime_error(const char* except_name, const char* sorce_name, const char* func_name, std::uint64_t line, const char* expression, const std::string& msg) + : std::runtime_error( + "exception : "s + except_name + '\n' + + " in " + sorce_name + "\n" + + " " + func_name + "() (line." + std::to_string(line) + ")\n" + + " follow by below\n" + + " " + expression + + ((msg.empty() || msg[0] == '\0') ? "\n" : "\n MESSAGE : " + msg + "\n") + ) + {} + runtime_error(const char* except_name, const char* sorce_name, const char* func_name, std::uint64_t line, const std::string& msg) + : std::runtime_error( + "exception : "s + except_name + '\n' + + " in " + sorce_name + "\n" + + " " + func_name + "() (line." + std::to_string(line) + ")\n" + + ((msg.empty() || msg[0] == '\0') ? "\n" : " MESSAGE : " + msg + "\n") + ) + {} + public: + runtime_error(const char* sorce_name, const char* func_name, std::uint64_t line, const char* expression, const std::string& msg) + : runtime_error("runtime_error", sorce_name, func_name, line, expression, msg) {} + runtime_error(const char* sorce_name, const char* func_name, std::uint64_t line, const std::string& msg) + : runtime_error("runtime_error", sorce_name, func_name, line, msg) {} + }; + + } + using exception::runtime_error; +} +#endif //DXLE_INC_EXCEPTION_RUNTIME_ERROR_HPP_ \ No newline at end of file diff --git a/dxlibex/exception/sound_exception.hpp b/dxlibex/exception/sound_exception.hpp new file mode 100644 index 0000000..23751a1 --- /dev/null +++ b/dxlibex/exception/sound_exception.hpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (C) 2015-2016 DxLibEx project + https://github.com/Nagarei/DxLibEx/ + + Distributed under the Boost Software License, Version 1.0. + (See http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef DXLE_INC_EXCEPTION_SOUND_EXCEPTION_HPP_ +#define DXLE_INC_EXCEPTION_SOUND_EXCEPTION_HPP_ +#include "dxlibex/exception/runtime_error.hpp" +#define DXLE_SOUND_ERROR_THROW_WITH_MESSAGE( MESSAGE ) throw dxle::sound_error(__FILE__, __FUNCTION__, __LINE__, MESSAGE) +#define DXLE_SOUND_ERROR_THROW_WITH_MESSAGE_IF( EXPR, MESSAGE ) if( EXPR ) throw dxle::sound_error(__FILE__, __FUNCTION__, __LINE__, #EXPR, MESSAGE) + +namespace dxle { + namespace exception{ + class sound_error : public dxle::exception::runtime_error { + public: + sound_error(const char* sorce_name, const char* func_name, std::uint64_t line, const char* expression, const std::string& msg) + : dxle::exception::runtime_error("sound_error", sorce_name, func_name, line, expression, msg) {} + sound_error(const char* sorce_name, const char* func_name, std::uint64_t line, const std::string& msg) + : dxle::exception::runtime_error("sound_error", sorce_name, func_name, line, msg) {} + }; + + } + using exception::sound_error; +} + +#endif //DXLE_INC_EXCEPTION_SOUND_EXCEPTION_HPP_ \ No newline at end of file