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

Document getting source_locations #1065

Open
computerquip-work opened this issue Jan 8, 2025 · 2 comments
Open

Document getting source_locations #1065

computerquip-work opened this issue Jan 8, 2025 · 2 comments

Comments

@computerquip-work
Copy link

I was struggling a bit getting reasonable error codes. I use the exception-based API for readability purposes. Most of these functions take a source_location parameter but it turns out that the location information is lost when the exception is thrown. For example a call to at() on a json::object will drop the information and instead have the call site of the internal function:

value const&
object::
at(string_view key, source_location const& loc) const&
{
    return try_at(key).value(loc);
}

try_at gets called and throws so loc being set in the result type doesn't matter.
Is there a decent way to avoid this short of wrapping everything?

@computerquip-work
Copy link
Author

computerquip-work commented Jan 8, 2025

Welp, I'm wrong here. There's two source_location objects being stored, one in the ec and one in the location_ over in throw_location. I thought the macro in try_at conditionally threw if exceptions were enabled but I was obviously wrong. In order to get the correct throw location, seems a call to get_throw_location has to be made. I guess I learned a bit more about boost exceptions today. Sorry fro the clutter.

@grisumbras
Copy link
Member

Sorry fro the clutter.

No problem. I should really document how to get the corresponding source_locations. The fact that you were confused by them highlights it. I'm reopening the issue and repurposing it for tracking documentation for dealing with source_locations.

@grisumbras grisumbras reopened this Jan 9, 2025
@grisumbras grisumbras changed the title source_location contains weird call site Document getting source_locations Jan 9, 2025
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

2 participants