|
Boost : |
From: rajesh daggumati (rajeshdaggumati9999_at_[hidden])
Date: 2021-10-17 11:41:52
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_cast<std::bad_alloc*>(e))
{
return new std::bad_alloc(*(dynamic_cast<std::bad_alloc*>(e)));
}
else if (dynamic_cast<std::bad_cast*>(e))
{
return new
std::bad_cast(*(dynamic_cast<std::bad_cast*>(e)));
}
else if (dynamic_cast<std::bad_typeid*>(e))
{
return new
std::bad_typeid(*(dynamic_cast<std::bad_typeid*>(e)));
}
else if (dynamic_cast<std::bad_exception*>(e))
{
return new
std::bad_exception(*(dynamic_cast<std::bad_exception*>(e)));
}
else if (dynamic_cast<std::domain_error*>(e))
{
return new
std::domain_error(*(dynamic_cast<std::domain_error*>(e)));
}
else if (dynamic_cast<std::invalid_argument*>(e))
{
return new
std::invalid_argument(*(dynamic_cast<std::invalid_argument*>(e)));
}
else if (dynamic_cast<std::length_error*>(e))
{
return new
std::length_error(*(dynamic_cast<std::length_error*>(e)));
}
else if (dynamic_cast<std::out_of_range*>(e))
{
return new
std::out_of_range(*(dynamic_cast<std::out_of_range*>(e)));
}
else if (dynamic_cast<std::overflow_error*>(e))
{
return new
std::overflow_error(*(dynamic_cast<std::overflow_error*>(e)));
}
else if (dynamic_cast<std::range_error*>(e))
{
return new
std::range_error(*(dynamic_cast<std::range_error*>(e)));
}
else if (dynamic_cast<std::underflow_error*>(e))
{
return new
std::underflow_error(*(dynamic_cast<std::underflow_error*>(e)));
}
else if (dynamic_cast<std::runtime_error*>(e))
{
return new
std::runtime_error(*(dynamic_cast<std::runtime_error*>(e)));
}
else if (dynamic_cast<std::exception*>(e))
{
return new
std::exception(*(dynamic_cast<std::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]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk