X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fexcept.h;h=f4319f6d3dd5108584d8f01218c3b5bfa6fef89a;hb=7ec897903893b6bd5f2a595191fd121a075ed430;hp=f28b6d27604c4d016cc423e0e0409a26c009ca13;hpb=6f43b14a9407b32ded43c4a1d94f8867ff61ff50;p=casparcg diff --git a/common/except.h b/common/except.h index f28b6d276..f4319f6d3 100644 --- a/common/except.h +++ b/common/except.h @@ -26,19 +26,23 @@ #include "os/stack_trace.h" #include +#include + #include #include #include +#include namespace caspar { -typedef boost::error_info arg_name_info_t; -typedef boost::error_info arg_value_info_t; -typedef boost::error_info msg_info_t; -typedef boost::error_info call_stack_info_t; -typedef boost::error_info error_info_t; -typedef boost::error_info source_info_t; -typedef boost::error_info file_name_info_t; +typedef boost::error_info arg_name_info_t; +typedef boost::error_info arg_value_info_t; +typedef boost::error_info msg_info_t; +typedef boost::error_info call_stack_info_t; +typedef boost::error_info error_info_t; +typedef boost::error_info source_info_t; +typedef boost::error_info file_name_info_t; +typedef boost::error_info context_info_t; template inline arg_name_info_t arg_name_info(const T& str) {return arg_name_info_t(u8(str));} @@ -53,7 +57,9 @@ inline error_info_t error_info(const T& str) {return error_info_t(u8(str));} template inline source_info_t source_info(const T& str) {return source_info_t(u8(str));} template -inline file_name_info_t file_name_info(const T& str) {return file_name_info_t(u8(str));} +inline file_name_info_t file_name_info(const T& str) {return file_name_info_t(u8(str));} +template +inline context_info_t context_info(const T& str) {return context_info_t(u8(str));} typedef boost::error_info line_info; typedef boost::error_info nested_exception; @@ -61,13 +67,10 @@ typedef boost::error_info nest struct caspar_exception : virtual boost::exception, virtual std::exception { caspar_exception(){} - explicit caspar_exception(const char* msg) : msg_(msg) {} const char* what() const throw() override { - return msg_; + return boost::diagnostic_information_what(*this); } -private: - const char* msg_ = ""; }; struct io_error : virtual caspar_exception {}; @@ -79,16 +82,52 @@ struct file_write_error : virtual io_error {}; struct invalid_argument : virtual caspar_exception {}; struct null_argument : virtual invalid_argument {}; struct out_of_range : virtual invalid_argument {}; +struct programming_error : virtual caspar_exception {}; struct bad_alloc : virtual caspar_exception {}; struct invalid_operation : virtual caspar_exception {}; struct operation_failed : virtual caspar_exception {}; struct timed_out : virtual caspar_exception {}; -struct not_supported : virtual caspar_exception {}; struct not_implemented : virtual caspar_exception {}; -#define CASPAR_THROW_EXCEPTION(e) BOOST_THROW_EXCEPTION(e << call_stack_info(caspar::get_call_stack())) +struct user_error : virtual caspar_exception {}; +struct expected_user_error : virtual user_error {}; +struct not_supported : virtual user_error {}; + +std::string get_context(); + +class scoped_context : boost::noncopyable +{ +public: + scoped_context(); + scoped_context(std::string msg); + template + scoped_context(Str msg) + : scoped_context(u8(std::move(msg))) + { + } + + ~scoped_context(); + void replace_msg(std::string msg); + template + void replace_msg(std::string msg) + { + replace_msg(u8(std::move(msg))); + } + void clear_msg(); +private: + std::list& for_thread_; + std::string* msg_; +}; + +#define _CASPAR_GENERATE_UNIQUE_IDENTIFIER_CAT(name, line) name##line +#define _CASPAR_GENERATE_UNIQUE_IDENTIFIER(name, line) _CASPAR_GENERATE_UNIQUE_IDENTIFIER_CAT(name, line) +#define CASPAR_SCOPED_CONTEXT_MSG(ctx_msg) ::caspar::scoped_context _CASPAR_GENERATE_UNIQUE_IDENTIFIER(SCOPED_CONTEXT, __LINE__)(u8(ctx_msg)); + +#define CASPAR_THROW_EXCEPTION(e) BOOST_THROW_EXCEPTION(e << call_stack_info(caspar::get_call_stack()) << context_info(get_context())) + +std::string get_message_and_context(const caspar_exception& e); }