-
Notifications
You must be signed in to change notification settings - Fork 45
Add message to BadExpectedAccess. #104
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
Add message to BadExpectedAccess. #104
Conversation
|
We can't assume E is an error_code. We need to pass a message string to std::exception instead |
That sounds like an excellent plan. Where does it come from if not from |
|
Okay, the string is now being passed in. It is not an optional parameter because I don't think we should ever throw a raw |
861ec34 to
05aa811
Compare
05aa811 to
85d119b
Compare
| #if LUABRIDGE_HAS_EXCEPTIONS | ||
| if (!hasValue()) | ||
| throw BadExpectedAccess<E>(error()); | ||
| throw BadExpectedAccess<E>(error(), error().message()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E is a templated class and can be anything. Here you are assuming is has a "message" method. We should solve it differently, using a detector on the E::message method (or eventually a to_string(E)) free function on the type if defined, inside the BadExpectedAccess constructor.
|
Got an alternative one which doesn't create issues if you use an E error type without a See #110 |
I've been using
Stack<>::getto pull values off the Lua stack inside proxy constructors. When I pass in the wrong types, it is producing the generic error messagestd::exception.A way to fix this appears to be to implement the
whatmethod, so that's what this PR does. I am opening it as a draft for comment, because there may be ramifications I don't know about. I tried returningerror_.message().c_str()but that produced a garbage error message. Hence the newmsg_member variable.