Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter exceptions thrown by AutoDesired #27

Merged
merged 1 commit into from Aug 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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";
}