-
Notifications
You must be signed in to change notification settings - Fork 9
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
CAPTURE not displayed when exception is caught #177
Comments
That is an oversight. The destructor of the underlying capture object always pops the capture data when the object goes out of scope, including when unwinding the stack after an exception: snitch/include/snitch/snitch_capture.hpp Lines 17 to 19 in d663212
We should use the same logic as for sections, so the information is preserved when an exception is being handled: Lines 13 to 20 in d663212
Should be pretty straightforward, I'll take a look. Thanks for reporting this! |
Should be solved in #178. This change introduces another problem, but I think this is a more unusual scenario (and doctest and Catch2 seem similarly affected): try {
int i = 1;
CAPTURE(i);
throw std::runtime_error("bad");
} catch (...) {}
int j = 2;
CAPTURE(j);
CHECK(j == 1); In this example, the last I'll try to see if we can improve it, but I don't think there's a way to make it 100% do what we want. |
I can make the above work as expected (only capture
The only situation I could find that used to work but no longer does is the following: try {
int i = 1;
CAPTURE(i);
throw std::runtime_error("bad 1");
} catch (...) {
}
throw std::runtime_error("bad 2"); In this case, the unhandled exception "bad 2" will be reported with the captured value for Fixing this would require adding some extra code, like an empty try {
int i = 1;
CAPTURE(i);
throw std::runtime_error("bad 1");
} catch (...) {
}
CAPTURE();
throw std::runtime_error("bad 2"); |
One idea to brainstorm, not really thought through: In descructor of the capture object, you somehow tag "deleted captures" with current exception (std::current_exception). Then, in snitch exceptiom handler, if the exception being thrown is still the same as the one deleted captures are tagged with, you display them. Otherwise, you assume the exception that deleted those captures was handled, and don't show them. More robust solution could tag with |
That's an interesting idea. The problem is the exception pointer is not guaranteed to point to the same object on different calls to
This is platform-dependent; it would work fine on Linux, but not on Windows:
Demonstration: #include <exception>
#include <iostream>
struct SomeException {
int content = 42;
};
int main() {
std::exception_ptr ptr1;
std::exception_ptr ptr2;
try {
try {
throw SomeException{};
} catch (...) {
ptr1 = std::current_exception();
std::rethrow_exception(ptr1);
}
} catch (...) {
ptr2 = std::current_exception();
}
std::cout << (ptr1 == ptr2) << std::endl;
return 0;
} Outputs |
To avoid blocking this, I have opened another ticket: #179. The discussion can carry on there if we wish to fix this, but IMO this is a small enough edge case (and has easy enough workarounds) that it probably isn't worth fixing. |
Snitch (version 1.2.5.d663212) doesn't display CAPTURE-ed value, when displaying unexpected exception. Is there any particular reason for this, or just an oversight?
The for loop with CAPTURE is basically doing the same thing as catch2's GENERATE() macro. When you have several nested layers of those, captured information is very useful to find out when an exception happens.
The text was updated successfully, but these errors were encountered: