Files
nearby/fastpair/message_stream
Janusz Sobczak 7a99b5e0a3 Specialize ExceptionOr<bool>
ExceptionOr<T>::ok() returns true if the value is set. This can be misleading
for boolean types.
ExceptionOr<bool> result = SomeFunction();
if (result.ok()) {
 if (result.result() {
  // Case 1: SomeFunction returned true
 } else {
  // Case 2: SomeFunction returned false
} else {
  // Case 3: SomeFunction returned an exception
}
It's easy to overlook case 2.
The specialized ExceptionOr<bool>::ok() returns false in Case 2, which allows
us to write:
if (result) {
 // SomeFunction returned true
} else {
 // SomeFunction returned false or an exception
 // result.GetException() can be used if we need to handle different exceptions
 // differenty
}

PiperOrigin-RevId: 544715641
2023-06-30 11:59:43 -07:00
..
2023-06-16 16:14:14 -07:00
2023-03-15 18:42:39 -07:00
2023-05-12 16:56:55 -07:00
2023-05-12 16:56:55 -07:00
2023-05-12 16:56:55 -07:00
2023-03-15 18:42:39 -07:00