Exception handling in Protocol Buffers C++ -
i don't find in protocol buffers documentation exception handling in c++. in javadoc has defined ones invalidprotocolbufferexception, not in c++.
sometimes ran program , crashes when finds missing fields in thinks valid message, stops , throws errors this:
[libprotobuf fatal google/protobuf/message_lite.cc:273] check failed: isinitialized(): can't serialize message of type "xxx" because missing required fields: yy, zz unknown file: failure c++ exception description "check failed: isinitialized(): can't serialize message of type "xxx" because missing required fields: yy, zz" thrown in test body.
the source code of message_lite.cc wrapped around "google_dcheck" or "initializationerrormessage"...
my application not allow exceptions halt program (not sure term in c++ no uncheckedexceptions), need way catch these, log errors, , return gracefully, in case messages got severely corrupted. there anyway doing that? why see this post indicating sort of google::protobuf::fatalexception
couldn't find documentations around (only fatalexception not enough also).
thanks!
the failure seeing indicates there bug in program -- program has requested serialize message without having filled in required fields first. think of segmentation fault. shouldn't try catch exception -- should instead fix app exception never happens in first place.
note check dcheck
, meaning checked in debug builds. in release builds (when ndebug
defined), check skipped , message written though not valid. so, don't have worry crashing application in production, while debugging.
(technically catch google::protobuf::fatalexception
, protobuf code not designed exception-safe. originally, check failures abort program. looks fatalexception
added recently, since code not exception-safe, it's you'll have memory leaks time fatalexception
thrown. so, should treat abort()
.)
Comments
Post a Comment