Reputation: 18109
I'm always checking the return value of Message::GetDescriptor()
before using it, but when would it ever return null? Is it perhaps unnecessary to check the return value?
The docs:
Declaration:
const Descriptor *
Message::GetDescriptor() const
Upvotes: 0
Views: 436
Reputation: 2382
You should always check return type of possibly every API that you code invokes, and should never make any kind of assumption however reliable the API may be. API s fail for a variety of reasons beyond human control:-
Since the API is from Google making a naive assumption that the 4th reason can never be true simply reduces the robustness of your software. For 99.99% of times it might just seem to be a redundant check or an over protective code - but for that 0.01% times when it fails you have unreliable behavior from your software
The costliest bugs that could have easily been avoided (if not fixed), from my experience over the years, are a result overlooking simple and basic error handling
Upvotes: 1
Reputation: 109
You don't have to check it, for each message you should get a non NULL pointer.
Upvotes: 0