Make associative container out-of-range exception provide missing key
authorOgnjen Dragoljevic <plamenko@fb.com>
Wed, 1 Nov 2017 22:54:38 +0000 (15:54 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 1 Nov 2017 23:10:02 +0000 (16:10 -0700)
commite75cf21f157eee116bd55cbffa68de02831ed775
tree23e2fdad75ccd621c9ead1481238e7aa725d9f09
parent968945c5e981c50746ba2f71293310a4536f96e1
Make associative container out-of-range exception provide missing key

Summary:
When the key is missing, the standard associative containers throw an exception like `unordered_map::at: key not found`. That's nice, but it would be even better if we would actually know what key is missing. This is not an issue when one is accessing the container directly, but when that access happens several levels deep, such as here within folly formatting logic, we have no way of knowing what key was missing. This poses some difficulties in presenting error to the user.
This change makes folly format throw a subclass of `std::out_of_range` exception on a missing key when a string keyed associative container is used for providing parameters. That subclass stores the actual key used so it can be accessed in the exception handler. Existing callers can still catch `std::out_of_range` so they should be unaffected by this change.

Reviewed By: ot, yfeldblum

Differential Revision: D6202184

fbshipit-source-id: b8a6740aaccc5d8914ad7d099c8b901427f00083
folly/Format-inl.h
folly/Format.cpp
folly/Format.h
folly/test/FormatTest.cpp