You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
absl::Status module has a bunch of pre-defined error code (enum class StatusCode) which is good, but what if user what their own error code?
Currently, my colleague are using raw_code() as a way to extend more error codes. It's hacky, I noticed that absl::Status will static_cast<StatusCode>(raw_code()), so it will cause UB if we defined a error code which int value is larger than 20 (out of the range of absl::StatusCode enum int value). I'd rather find a another way for it...
I also find the way of error handling absl::Status provides is very similar to Result<T, E> in Rust. You return a struct contains both return value and error information(if any). It's really a decent alternatives to exception, and I hope it's more extensible.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
absl::Status
module has a bunch of pre-defined error code (enum class StatusCode
) which is good, but what if user what their own error code?Currently, my colleague are using
raw_code()
as a way to extend more error codes. It's hacky, I noticed thatabsl::Status
willstatic_cast<StatusCode>(raw_code())
, so it will cause UB if we defined a error code which int value is larger than 20 (out of the range ofabsl::StatusCode
enum int value). I'd rather find a another way for it...I also find the way of error handling
absl::Status
provides is very similar toResult<T, E>
in Rust. You return a struct contains both return value and error information(if any). It's really a decent alternatives to exception, and I hope it's more extensible.Beta Was this translation helpful? Give feedback.
All reactions