Struct ErrorEvent

Synopsis

#include <src/uvw/emitter.h>

struct ErrorEvent

Description

The ErrorEvent event.

Custom wrapper around error constants of libuv.

Mentioned in

Methods

ErrorEvent
codeGets the underlying error code, that is an error constant of libuv.
nameReturns the error name for the given error code.
operator boolChecks if the event contains a valid error code.
translateReturns the libuv error code equivalent to the given platform dependent error code.
whatReturns the error message for the given error code.

Source

Lines 24-76 in src/uvw/emitter.h.

struct ErrorEvent {
    template<typename U, typename = std::enable_if_t<std::is_integral_v<U>>>
    explicit ErrorEvent(U val) noexcept
        : ec{static_cast<int>(val)}
    {}

    /**
     * @brief Returns the `libuv` error code equivalent to the given platform dependent error code.
     *
     * It returns:
     * * POSIX error codes on Unix (the ones stored in errno).
     * * Win32 error codes on Windows (those returned by GetLastError() or WSAGetLastError()).
     *
     * If `sys` is already a `libuv` error code, it is simply returned.
     *
     * @param sys A platform dependent error code.
     * @return The `libuv` error code equivalent to the given platform dependent error code.
     */
    static int translate(int sys) noexcept;

    /**
     * @brief Returns the error message for the given error code.
     *
     * Leaks a few bytes of memory when you call it with an unknown error code.
     *
     * @return The error message for the given error code.
     */
    const char * what() const noexcept;

    /**
     * @brief Returns the error name for the given error code.
     *
     * Leaks a few bytes of memory when you call it with an unknown error code.
     *
     * @return The error name for the given error code.
     */
    const char * name() const noexcept;

    /**
     * @brief Gets the underlying error code, that is an error constant of `libuv`.
     * @return The underlying error code.
     */
    int code() const noexcept;

    /**
     * @brief Checks if the event contains a valid error code.
     * @return True in case of success, false otherwise.
     */
    explicit operator bool() const noexcept;

private:
    const int ec;
};





Add Discussion as Guest

Log in