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

Custom Exception types #29

Closed
philsquared opened this issue Apr 19, 2011 · 2 comments
Closed

Custom Exception types #29

philsquared opened this issue Apr 19, 2011 · 2 comments

Comments

@philsquared
Copy link
Collaborator

Currently, exceptions not derived from std::exception (other than raw strings) are caught by CATCH, but it doesn't know how to get any messages out.
A mechanism is needed to be able to specify custom exception types so more informative messages can be given.

I can't think of any clean (portable) ways to do this OTTOMH, but one way to "hack it" would be to have a macro, CUSTOM_EXCEPTION_TYPE, as well as CUSTOM_EXCEPTION_HANDLER, which would allow the user to specify a type and how to get the string out respectively.

This has a number of drawbacks. Apart from being very ugly it only allows one custom exception type to be specified (unless we have CUSTOM_EXCEPTION_TYPE2 etc), and the caller has to make sure the macros are defined before catch is included.

Any better ideas are very welcome!

@philsquared
Copy link
Collaborator Author

Thanks to James Bates, who suggested that a ... handler can call out to external functions that can rethrow within another try-catch and catch the exception by type there.

@philsquared
Copy link
Collaborator Author

Implemented. See CATCH_TRANSLATE_EXCEPTION

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant