Skip to content

Commit

Permalink
Filter exceptions thrown by AutoDesired
Browse files Browse the repository at this point in the history
  • Loading branch information
codemercenary committed Aug 4, 2014
1 parent c3b7e62 commit a3a1758
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions autowiring/Autowired.h
Expand Up @@ -281,7 +281,9 @@ class AutoRequired:
///
/// try {
/// AutoCurrentContext()->Inject<T>();
/// catch(...) {}
/// catch(...) {
/// AutoCurrentContext()->FilterException();
/// }
/// Autowired<T> foo;
///
/// Users who wish to know whether an exception was thrown may replace uses of AutoDesired with the above
Expand All @@ -294,7 +296,9 @@ class AutoDesired:
public:
AutoDesired(void) {
try { AutoRequired<T>(); }
catch(...) {}
catch(...) {
CoreContext::CurrentContext()->FilterException();
}
}
};

Expand Down
28 changes: 28 additions & 0 deletions src/autowiring/test/AutowiringTest.cpp
Expand Up @@ -75,4 +75,32 @@ TEST_F(AutowiringTest, PathologicalAutowiringRace) {
// Now insert at about the same time as other threads are waking up. If there are synchronization problems
// in spin-up or tear-down,
AutoRequired<SimpleObject>();
}

class ChecksForExceptions:
public ExceptionFilter
{
public:
ChecksForExceptions(void):
m_called(false)
{}

bool m_called;

void Filter(void) override {
m_called = true;
}
};

class ThrowsExceptionInCtor {
public:
ThrowsExceptionInCtor(void) {
throw std::exception();
}
};

TEST_F(AutowiringTest, AUTOTHROW_CanSeeThrownAutoDesiredExceptions) {
AutoRequired<ChecksForExceptions> cfe;
AutoDesired<ThrowsExceptionInCtor>();
ASSERT_TRUE(cfe->m_called) << "Exception was not caught by exception filter in Autowiring context";
}

0 comments on commit a3a1758

Please sign in to comment.