Skip to content

Commit

Permalink
Merge pull request #777 from leapmotion/ref-harmlesserr
Browse files Browse the repository at this point in the history
Render `CreateInternal` exceptions harmless
  • Loading branch information
Veronica Zheng committed Oct 15, 2015
2 parents 3cc63d6 + 874b31c commit b68000b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/autowiring/CoreContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ CoreContext::~CoreContext(void) {
std::shared_ptr<CoreContext> CoreContext::CreateInternal(t_pfnCreate pfnCreate)
{
// don't allow new children if shutting down
if(IsShutdown())
throw autowiring_error("Cannot create a child context; this context is already shut down");
if (IsShutdown())
throw dispatch_aborted_exception("Cannot create a child context; this context is already shut down");

t_childList::iterator childIterator;
{
Expand Down
24 changes: 24 additions & 0 deletions src/autowiring/test/CoreContextTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,27 @@ TEST_F(CoreContextTest, InitiateAssertsSignals) {
}
ASSERT_TRUE(*teardown) << "Teardown handler not correctly notified on context teardown";
}

namespace {
class TriesToCreateChild :
public CoreThread
{
public:
TriesToCreateChild(void) :
CoreThread("TriesToCreateChild")
{}

void Run(void) override {
while (!ShouldStop());
AutoCreateContext();
}
};
}

TEST_F(CoreContextTest, TerminatedContextHarmless) {
AutoCurrentContext ctxt;
ctxt->Initiate();
AutoRequired<TriesToCreateChild>{};
ctxt->SignalShutdown();
ASSERT_THROW(ctxt->Create<void>(), dispatch_aborted_exception) << "An exception should have been thrown when attempting to create a child from a terminated context";
}

0 comments on commit b68000b

Please sign in to comment.