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
narrowing_error with more information #761
Conversation
- added type trait is_streamable - added what to narrowing_error (not optimized for MSVC, just standard C++ stuff) - instead of "Unknown exception" we now get either "<type_from> <value> to <type_to>" or "<type_from> to <type_to>"
72f4846
to
6e0749c
Compare
@beinhaerter I am worried about increasing binary size due to pulling all io libraries - any thoughts? Can this be optional? |
There is a problem with 'std::string _what;' if you throw this exception from debug dll and try to catch in release exe (or vice versa) in MSVC - debug std::string != release std::string. |
@annagrin Understood, good point. In my personal use case I don't mind because I am using iostream anyway (and I want to see the value!) but in a more general approach this matters. The question now for me is: how much interest exists in having a more verbose exception? If that is not of interest, there is no need to do more work on it here. If it is of interest, then let's talk about how I can improve it. Possible ways could be:
@dmateja Good point, but I am not sure if this is something that is supported/relevant. With regard to the one definition rule that would mean that you must have a library interface that is very restricted. But of course - GSL is a general purpose library and should not make unnecessary assumptions about the use cases. Maybe someone from the MS staff can share his/her sights? |
C++ Core Guidelines editors' call: This seems to be asking for a debugging aid that can be expensive in release mode. It could be added in debug mode only, and then only for projects that are not supposed to change their dependencies between debug and release modes (which seems undesirable because it limits use of GSL in such projects). Better would be to use the debugger to view the information if an exception is thrown, such as by setting a breakpoint in the implementation of |
My debug output also helps when a |
This is done to provide as much debug information as possible in case of a narrowing_error exception.
I am not very experienced with type traits, so any idea how to do it better is very welcome. I took the code for is_streamable from https://stackoverflow.com/a/22759368/1023911.
I tested the code given this short program (output is given in the comments):