Hi Team, I need to create an object for catched exception . class exception: virtual public std::exception ,virtual public boost::exception {} inside my application code, try{ boost::rethrow_exception(exceptr)} catch(std::exception &e) { std::exception *e = stacktoHeapObject(e); } static std::exception* stacktoHeapObj(std::exception* e) { if (dynamic_caststd::bad_alloc*(e)) { return new std::bad_alloc(*(dynamic_caststd::bad_alloc*(e))); } else if (dynamic_caststd::bad_cast*(e)) { return new std::bad_cast(*(dynamic_caststd::bad_cast*(e))); } else if (dynamic_caststd::bad_typeid*(e)) { return new std::bad_typeid(*(dynamic_caststd::bad_typeid*(e))); } else if (dynamic_caststd::bad_exception*(e)) { return new std::bad_exception(*(dynamic_caststd::bad_exception*(e))); } else if (dynamic_caststd::domain_error*(e)) { return new std::domain_error(*(dynamic_caststd::domain_error*(e))); } else if (dynamic_caststd::invalid_argument*(e)) { return new std::invalid_argument(*(dynamic_caststd::invalid_argument*(e))); } else if (dynamic_caststd::length_error*(e)) { return new std::length_error(*(dynamic_caststd::length_error*(e))); } else if (dynamic_caststd::out_of_range*(e)) { return new std::out_of_range(*(dynamic_caststd::out_of_range*(e))); } else if (dynamic_caststd::overflow_error*(e)) { return new std::overflow_error(*(dynamic_caststd::overflow_error*(e))); } else if (dynamic_caststd::range_error*(e)) { return new std::range_error(*(dynamic_caststd::range_error*(e))); } else if (dynamic_caststd::underflow_error*(e)) { return new std::underflow_error(*(dynamic_caststd::underflow_error*(e))); } else if (dynamic_caststd::runtime_error*(e)) { return new std::runtime_error(*(dynamic_caststd::runtime_error*(e))); } else if (dynamic_caststd::exception*(e)) { return new std::exception(*(dynamic_caststd::exception*(e))); } } I have coded by taking order reference of below pic. please help me to get classes names in boost:exception which are not in std::exception . if they are in boost::exception only then how to catch that and send to stackToHeapObj and what order i need to follow to add those if checks. try { boost::rethrow_exception(exptr) } here in catch block , we don't know which exception type we have in exptr(ie. std:: or boost:;) then How to catch them. if i use std::exception in catch block then if exptr throws boost::exception type then ... and viceversa..? Please help me to clarify above queries [image: image.png]
On Sun, Oct 17, 2021 at 6:47 AM rajesh daggumati via Boost
...
I don't know exactly what is going on here, but I am having trouble seeing the necessity. Maybe you could explain exactly what you are trying to do, because this business of doing all these casts is not something that I have seen before. Is it possible that this function could be helpful to you? https://en.cppreference.com/w/cpp/error/make_exception_ptr Regards
My application code was handled with shared_pointers.
here boost::rethrow_exception is throwing exception object (which is
created in stack..) but shared pointers need objects which are created on
heap SO for that , I am converting object from stack to heap by
copying it.(ie. classname *c1 = new classname(stack_object)).
I have typecasted all std::exceptions
I have two queries
1. I need some class whose 2 childs are std::exception and
boost::exception so that I can type cast based on if checks..
2. The exception classes which are in boost::exception and not in
std::exception
Please help me to clarify above 2 queries.
On Sun, 17 Oct 2021 at 19:44, Vinnie Falco
On Sun, Oct 17, 2021 at 6:47 AM rajesh daggumati via Boost
wrote: ...
I don't know exactly what is going on here, but I am having trouble seeing the necessity. Maybe you could explain exactly what you are trying to do, because this business of doing all these casts is not something that I have seen before. Is it possible that this function could be helpful to you?
https://en.cppreference.com/w/cpp/error/make_exception_ptr
Regards
On Sun, Oct 17, 2021 at 9:21 AM rajesh daggumati via Boost < boost@lists.boost.org> wrote:
My application code was handled with shared_pointers. here boost::rethrow_exception is throwing exception object (which is created in stack..) but shared pointers need objects which are created on heap SO for that , I am converting object from stack to heap by copying it.(ie. classname *c1 = new classname(stack_object)).
It looks like you should use std::current_exception and holding exceptions in std::exception_ptr rather than std::shared_ptr. If using an old compiler that does not support these, Boost provides compatible alternatives.
try { BOOST_THROW_EXCEPTION(std::invalid_argument("Blah")); } catch (...) { boost::exception_ptr exception = boost::current_exception(); try { boost::rethrow_exception(exception); } catch() //exception is from std::invalid_argument do i need to give boost::excepion &e or std::exception &e in catch block My application code is having boost::exception and std::exception. I need a datatype to store both std::exception and boost::exception(other than boost::exception_ptr as everytime I need to rethrow and catch it and need to do everythng inside cathc block.. its not possible always) On Sun, 17 Oct 2021 at 21:40, rajesh daggumati < rajeshdaggumati9999@gmail.com> wrote:
My application code was handled with shared_pointers. here boost::rethrow_exception is throwing exception object (which is created in stack..) but shared pointers need objects which are created on heap SO for that , I am converting object from stack to heap by copying it.(ie. classname *c1 = new classname(stack_object)). I have typecasted all std::exceptions I have two queries 1. I need some class whose 2 childs are std::exception and boost::exception so that I can type cast based on if checks.. 2. The exception classes which are in boost::exception and not in std::exception
Please help me to clarify above 2 queries.
On Sun, 17 Oct 2021 at 19:44, Vinnie Falco
wrote: On Sun, Oct 17, 2021 at 6:47 AM rajesh daggumati via Boost
wrote: ...
I don't know exactly what is going on here, but I am having trouble seeing the necessity. Maybe you could explain exactly what you are trying to do, because this business of doing all these casts is not something that I have seen before. Is it possible that this function could be helpful to you?
https://en.cppreference.com/w/cpp/error/make_exception_ptr
Regards
try { BOOST_THROW_EXCEPTION(std::invalid_argument("Blah")); } catch (...) { boost::exception_ptr exception = boost::current_exception(); try { boost::rethrow_exception(exception); } catch() //exception is from std::invalid_argument do i need to give boost::excepion &e or std::exception &e in catch block My application code is having boost::exception and std::exception. I need a datatype to store both std::exception and boost::exception(other than boost::exception_ptr as everytime I need to rethrow and catch it and need to do everythng inside cathc block.. its not possible always) On Mon, 18 Oct 2021 at 16:48, rajesh daggumati < rajeshdaggumati9999@gmail.com> wrote:
try { BOOST_THROW_EXCEPTION(std::invalid_argument("Blah")); } catch (...) { boost::exception_ptr exception = boost::current_exception(); try { boost::rethrow_exception(exception); } catch() //exception is from std::invalid_argument do i need to give boost::excepion &e or std::exception &e in catch block
My application code is having boost::exception and std::exception. I need a datatype to store both std::exception and boost::exception(other than boost::exception_ptr as everytime I need to rethrow and catch it and need to do everythng inside cathc block.. its not possible always)
On Sun, 17 Oct 2021 at 21:40, rajesh daggumati < rajeshdaggumati9999@gmail.com> wrote:
My application code was handled with shared_pointers. here boost::rethrow_exception is throwing exception object (which is created in stack..) but shared pointers need objects which are created on heap SO for that , I am converting object from stack to heap by copying it.(ie. classname *c1 = new classname(stack_object)). I have typecasted all std::exceptions I have two queries 1. I need some class whose 2 childs are std::exception and boost::exception so that I can type cast based on if checks.. 2. The exception classes which are in boost::exception and not in std::exception
Please help me to clarify above 2 queries.
On Sun, 17 Oct 2021 at 19:44, Vinnie Falco
wrote: On Sun, Oct 17, 2021 at 6:47 AM rajesh daggumati via Boost
wrote: ...
I don't know exactly what is going on here, but I am having trouble seeing the necessity. Maybe you could explain exactly what you are trying to do, because this business of doing all these casts is not something that I have seen before. Is it possible that this function could be helpful to you?
https://en.cppreference.com/w/cpp/error/make_exception_ptr
Regards
On Mon, Oct 18, 2021 at 6:01 AM rajesh daggumati via Boost < boost@lists.boost.org> wrote:
try { BOOST_THROW_EXCEPTION(std::invalid_argument("Blah")); } catch (...) { boost::exception_ptr exception = boost::current_exception(); try { boost::rethrow_exception(exception); } catch() //exception is from std::invalid_argument do i need to give boost::excepion &e or std::exception &e in catch block
My application code is having boost::exception and std::exception. I need a datatype to store both std::exception and boost::exception(other than boost::exception_ptr as everytime I need to rethrow and catch it and need to do everythng inside cathc block.. its not possible always)
If you can't handle the exception completely, you can rethrow the original exception like this: try { BOOST_THROW_EXCEPTION(std::invalid_argument("Blah")); } catch (...) { boost::exception_ptr exception = boost::current_exception(); try { boost::rethrow_exception(exception); } catch( std::exception & e ) { ... // partially handle std::exception throw; // rethrow original object } catch( boost::exception & e ) { ... // partially handle boost::exception throw; // rethrow original object } }
participants (3)
-
Emil Dotchevski
-
rajesh daggumati
-
Vinnie Falco