conversion issues from boost::exception_ptr to exception class shared_ptr
HI Team, // i have caught exception in exception_ptr and I and trying to convert to ExceptionPtr_t but I am facing issue at below derived->severity(). * unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.* *code snippet is :* *E*xceptionPtr_t ExceptionHelper::TryGetExceptionPtr(boost::exception_ptr exception) { ExceptionPtr_t result ; std::string res; if(!exception) return result; try { boost::rethrow_exception(exception) *}catch(boost::exception &e)* *{boost::throw_file::value_type const* throw_file_data = boost::get_error_info<boost::throw_file>(e);* *if(* *throw_file_data)* *{* * result = exceptionPtr_t(new ExceptionWrapper(exception,*throw_filed_data,true))* *}* *return result;* *}* class Exception : public virtual std::exception, public virtual boost::exception { protected: string what; serviorytype m_severity; public: explicit Exception(const std::string& what); virtual ~Exception() throw() {} // we have some member functions like severity(),setseverity(value)... } class ExceptionWrapper : public Exception { private: string m_what_inner; boost::exception_ptr m_inner; public: explict ExceptionWrapper(boost::exception_ptr inner,string &what() = std::string,bool copythrow = true); explict ExceptionWrapper(boost::exceptionPtr_t inner,string &what() = std::string,bool copythrow = true); virtual ~ExceptionWrapper() throw(){} // some methods like severity(),setSeverity(value),.....) } I was doing like: const Exception* derived = reinterPret_cast<const Exception*> (&exception)// here exception is type of exception_ptr if(derived) { derived->severity(); // here exception is coming... if i put this line in try block then its going for catch block and new exception is being rasied. if i dont put try block then *unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.* } Please help me to resolve this issue
On 9/29/21 1:24 PM, rajesh daggumati via Boost wrote:
HI Team, // i have caught exception in exception_ptr and I and trying to convert to ExceptionPtr_t
What is ExceptionPtr_t? Assuming it is a shared_ptr, as can be guessed from the title, you can't convert exception_ptr to shared_ptr (or any other smart-pointer) without copying the exception object.
but I am facing issue at below derived->severity(). * unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.*
*code snippet is :* *E*xceptionPtr_t ExceptionHelper::TryGetExceptionPtr(boost::exception_ptr exception) { ExceptionPtr_t result ; std::string res; if(!exception) return result; try { boost::rethrow_exception(exception) *}catch(boost::exception &e)*
*{boost::throw_file::value_type const* throw_file_data = boost::get_error_info<boost::throw_file>(e);* *if(* *throw_file_data)* *{* * result = exceptionPtr_t(new ExceptionWrapper(exception,*throw_filed_data,true))* *}* *return result;*
*}*
I was doing like:
const Exception* derived = reinterPret_cast<const Exception*> (&exception)// here exception is type of exception_ptr
You've been pointed to this being incorrect before: https://lists.boost.org/Archives/boost/2021/09/251987.php You're just accessing memory through an invalid pointer and getting an access violation.
participants (2)
-
Andrey Semashev
-
rajesh daggumati