Closed itamarcps closed 1 year ago
It is undefined behavior to use operator[]
on a const object for an array index that doesn't exist. You need to be sure that it exists first. If you want checked access, you need to use at()
instead. https://json.nlohmann.me/api/basic_json/operator%5B%5D/#notes
Thanks, using .at(idx)
works perfectly fine for me.
Description
try/catch block with a function taking const json& as a argument and accessing an array within the json doesn't catch.
Reproduction steps
Reproducible with the code included in this issue.
Expected vs. actual results
The function should be able to catch, if you take out the const from the argument, it catches successfully.
Minimal code example
Error messages
Compiler and operating system
gcc 10.2.1
Library version
C++20, Latest nlohmann/json release.
Validation
develop
branch is used.