WPILibC++ 2024.3.2
Error.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#ifndef WPINET_UV_ERROR_H_
6#define WPINET_UV_ERROR_H_
7
8#include <uv.h>
9
10namespace wpi::uv {
11
12/**
13 * Error code.
14 */
15class Error {
16 public:
17 Error() = default;
18 explicit Error(int err) : m_err(err) {}
19
20 /**
21 * Boolean conversion. Returns true if error, false if ok.
22 */
23 explicit operator bool() const { return m_err < 0; }
24
25 /**
26 * Returns the error code.
27 */
28 int code() const { return m_err; }
29
30 /**
31 * Returns the error message.
32 */
33 const char* str() const { return uv_strerror(m_err); }
34
35 /**
36 * Returns the error name.
37 */
38 const char* name() const { return uv_err_name(m_err); }
39
40 private:
41 int m_err{0};
42};
43
44} // namespace wpi::uv
45
46#endif // WPINET_UV_ERROR_H_
Error code.
Definition: Error.h:15
const char * name() const
Returns the error name.
Definition: Error.h:38
Error(int err)
Definition: Error.h:18
int code() const
Returns the error code.
Definition: Error.h:28
const char * str() const
Returns the error message.
Definition: Error.h:33
Error()=default
Definition: WebSocket.h:27
UV_EXTERN const char * uv_strerror(int err)
UV_EXTERN const char * uv_err_name(int err)