X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fexcept.h;h=f4319f6d3dd5108584d8f01218c3b5bfa6fef89a;hb=70235ae09df45c874e133fd4d3fcc1e6e34e993a;hp=d62b4d8da08e1737d331777a417f7b7733f84607;hpb=652dc1a2e64a8ff33f6d8498b0c394c4a51a6527;p=casparcg diff --git a/common/except.h b/common/except.h index d62b4d8da..f4319f6d3 100644 --- a/common/except.h +++ b/common/except.h @@ -26,9 +26,12 @@ #include "os/stack_trace.h" #include +#include + #include #include #include +#include namespace caspar { @@ -36,9 +39,10 @@ typedef boost::error_info arg_name_info_ 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 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));} @@ -54,6 +58,8 @@ 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));} +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; @@ -86,9 +92,42 @@ struct timed_out : virtual caspar_exception {}; struct not_implemented : virtual caspar_exception {}; struct user_error : virtual caspar_exception {}; +struct expected_user_error : virtual user_error {}; struct not_supported : virtual user_error {}; -#define CASPAR_THROW_EXCEPTION(e) BOOST_THROW_EXCEPTION(e << call_stack_info(caspar::get_call_stack())) +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); }