-
Notifications
You must be signed in to change notification settings - Fork 27
find_value: Add 'throw_if_not_present' #12
find_value: Add 'throw_if_not_present' #12
Conversation
lib/univalue.cpp
Outdated
| } | ||
|
|
||
| if (throw_if_not_present) { | ||
| throw int(-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in general we want to throw exceptions derived from std::exception. Univalue seems to use runtime_exception for other cases, so this may be sufficient.
Required in order to be able to distinguish between keys which do not exist
and those which exist but point to null values.
950819c to
e53c5e8
Compare
|
Changed to inherit from std::exception, also see bitcoin/bitcoin#12435 |
|
Which methods present you with missing fields? I'm curious to know where you need this. In any event, I don't think this is right. In C++ try/catch blocks are cheap, but throwing an exception is very expensive, because it requires unwinding the stack. The way I would be something like this: Then in the body if |
|
It's in the pull request on the bitcoin repo. In the JSON-RPC 2.0 spec if the 'id' field is not present in a request, then the request should be treated as a 'notification' and not responded to. The default-argument null pointer thing is clever. I'll change it over to use that instead. |
|
Needs rebase. |
|
PR title is misleading, please update. I think the |
|
Closing this for now, as the downstream work is not continuing. |
Required in order to be able to distinguish between keys which do not exist
and those which exist but point to null values.
If anyone has a better recommendation for which specific exception to throw here, or perhaps even a better way to do it, I'm all ears.