This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
I am in a in-path
- From: "Hotmail \(ArbolOne\)" <ArbolOne at hotmail dot ca>
- To: "gcc-help Mailing List" <gcc-help at gcc dot gnu dot org>, "MinGW-64 Mailinglist" <mingw-w64-public at lists dot sourceforge dot net>
- Date: Wed, 27 May 2015 19:15:17 -0400
- Subject: I am in a in-path
- Authentication-results: sourceware.org; auth=none
I am in a in-path. I wrote a class that handles exceptions,
namespace abc{
class Exception{...}; // This is my very large Exception class
}
The way I'd like to use this class is by creating a smart pointer to it in
each newly created class, i.e.
namespace abc{
class m_class0000001{
private:
std::shared_ptr<abc::Exception> apex;
public:
m_class(){apex.reset(new abc::Exception());}
m_method(){
apex->setException(...);
throw apex;
}
};
}
auto apex = std::make_shared<abc::Exception>();
int main() {
try {
auto obj = std::make_shared<abc::m_class0000001>();
obj->m_method();
} catch(std::shared_ptr<abc::Exception>& e) {
e->DisplaySomething();
}
return 0;
}
But this can be very expensive, since this possibly-very-large class will be
created in thousands of classes.
On the other hand, I could create the object when or where the exception
occurs, like this:
namespace abc{
class m_class0000001{
private:
...
public:
m_class(){}
m_method(){
... /* I don't even know if this is possible */
auto obj = std::make_shared<abc::Exception>();
apex->setException(...);
throw apex;
}
};
}
This creates another problem, what if the exception is std::mem_alloc, I
would ran out of memory, thus I wouldn't be able to create another object.
I know, I know, this is not a C++ question, but, as I said, I am in a
in-path, I don't know what to do in this case.
Any help would be most appreciated.