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

Exception messages for BadAnyCastException are unhelpful #181

Closed
tmwnewbold opened this Issue Feb 27, 2017 · 1 comment

Comments

Projects
2 participants
@tmwnewbold

tmwnewbold commented Feb 27, 2017

The messages returned from BadAnyCastException::what() are unhelpful while debugging failures. The message appears to be just a static string:

Failed to convert between const Any types

any_cast has access both to the actual type contained within the Any as well as the C++ type that was the requested target type. The message should contain both of these in order to help developers troubleshoot failed casts.

@jeffdiclemente jeffdiclemente self-assigned this Mar 10, 2017

@jeffdiclemente jeffdiclemente added this to Planned in Release 3.1 Mar 13, 2017

@jeffdiclemente

This comment has been minimized.

Show comment
Hide comment
@jeffdiclemente

jeffdiclemente Mar 14, 2017

Contributor

@tmwnewbold
Yes, the exception message can be better. I am planning on changing the message to:

Failed to convert from const Any type [type name] to target type [type name]

As an example, given this code snippet:

const Any uncastableConstAny(0.2);
(void)any_cast<std::string>(uncastableConstAny);

The BadAnyCastException message would be:

Failed to convert from const Any type double to target type class std::basic_string<char,struct std::char_traits,class std::allocator >

Contributor

jeffdiclemente commented Mar 14, 2017

@tmwnewbold
Yes, the exception message can be better. I am planning on changing the message to:

Failed to convert from const Any type [type name] to target type [type name]

As an example, given this code snippet:

const Any uncastableConstAny(0.2);
(void)any_cast<std::string>(uncastableConstAny);

The BadAnyCastException message would be:

Failed to convert from const Any type double to target type class std::basic_string<char,struct std::char_traits,class std::allocator >

@jeffdiclemente jeffdiclemente moved this from Planned to In Progress in Release 3.1 Mar 15, 2017

jeffdiclemente added a commit that referenced this issue Mar 17, 2017

Improve BadAnyCastException message
Fixes #181
 
Signed-off-by: The MathWorks, Inc. Roy.Lurie@mathworks.com

jeffdiclemente added a commit that referenced this issue Apr 21, 2017

Improve BadAnyCastException message
Fixes #181
 
Signed-off-by: The MathWorks, Inc. Roy.Lurie@mathworks.com

@jeffdiclemente jeffdiclemente moved this from In Progress to Done in Release 3.1 May 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment