mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
nearby: snapshot as of cl/296436629
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: I2cf5bf225b76f4c1541954651f3a7544a14e0cec
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#ifndef PLATFORM_EXCEPTION_H_
|
||||
#define PLATFORM_EXCEPTION_H_
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
|
||||
struct Exception {
|
||||
enum Value {
|
||||
NONE,
|
||||
IO,
|
||||
INTERRUPTED,
|
||||
INVALID_PROTOCOL_BUFFER,
|
||||
EXECUTION,
|
||||
};
|
||||
};
|
||||
|
||||
// ExceptionOr models the concept of the return value of a function that might
|
||||
// throw an exception.
|
||||
//
|
||||
// If ok() returns true, result() is a usable return value. Otherwise,
|
||||
// exception() explains why such a value is not present.
|
||||
//
|
||||
// A typical pattern of usage is as follows:
|
||||
//
|
||||
// if (!e.ok()) {
|
||||
// if (Exception::EXCEPTION_TYPE_1 == e.exception()) {
|
||||
// // Handle Exception::EXCEPTION_TYPE_1.
|
||||
// } else if (Exception::EXCEPTION_TYPE_2 == e.exception()) {
|
||||
// // Handle Exception::EXCEPTION_TYPE_2.
|
||||
// }
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Use e.result().
|
||||
template <typename T>
|
||||
class ExceptionOr {
|
||||
public:
|
||||
explicit ExceptionOr(T result);
|
||||
explicit ExceptionOr(Exception::Value exception);
|
||||
|
||||
bool ok() const;
|
||||
|
||||
T result() const;
|
||||
Exception::Value exception() const;
|
||||
|
||||
private:
|
||||
T result_;
|
||||
Exception::Value exception_;
|
||||
};
|
||||
|
||||
} // namespace nearby
|
||||
} // namespace location
|
||||
|
||||
#include "platform/exception.cc"
|
||||
|
||||
#endif // PLATFORM_EXCEPTION_H_
|
||||
Reference in New Issue
Block a user