WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
Errors.hpp File Reference
#include <stdint.h>
#include <memory>
#include <stdexcept>
#include <string>
#include <fmt/format.h>
#include "wpi/system/WPIErrors.mac"
#include "wpi/system/WPIWarnings.mac"

Go to the source code of this file.

Classes

class  wpi::RuntimeError
 Runtime error exception. More...

Namespaces

namespace  wpi
namespace  wpi::err
namespace  wpi::warn

Macros

#define S(label, offset, message)
#define S(label, offset, message)
#define WPILIB_ReportError(status, format, ...)
 Reports an error to the driver station (using HAL_SendError).
#define WPILIB_ReportWarning(format, ...)
 Reports a warning to the driver station (using HAL_SendError).
#define WPILIB_MakeError(status, format, ...)
 Makes a runtime error exception object.
#define WPILIB_CheckErrorStatus(status, format, ...)
 Checks a status code and depending on its value, either throws a RuntimeError exception, calls ReportError, or does nothing (if no error).
#define WPILIB_AssertMessage(condition, format, ...)
#define WPILIB_Assert(condition)

Functions

const char * wpi::GetErrorMessage (int32_t *code)
 Gets error message string for an error code.
void wpi::ReportErrorV (int32_t status, const char *fileName, int lineNumber, const char *funcName, fmt::string_view format, fmt::format_args args)
 Reports an error to the driver station (using HAL_SendError).
template<typename... Args>
void wpi::ReportError (int32_t status, const char *fileName, int lineNumber, const char *funcName, fmt::string_view format, Args &&... args)
 Reports an error to the driver station (using HAL_SendError).
RuntimeError wpi::MakeErrorV (int32_t status, const char *fileName, int lineNumber, const char *funcName, fmt::string_view format, fmt::format_args args)
 Makes a runtime error exception object.
template<typename... Args>
RuntimeError wpi::MakeError (int32_t status, const char *fileName, int lineNumber, const char *funcName, fmt::string_view format, Args &&... args)
 wpi::err::S (ChannelIndexOutOfRange, -45, "Allocating channel that is out of range") S(ResourceAlreadyAllocated
Attempted to reuse an allocated resource wpi::err::S (NullParameter, -5, "A pointer parameter to a method is nullptr") S(Timeout
Attempted to reuse an allocated resource A timeout has been exceeded wpi::err::S (ParameterOutOfRange, -28, "A parameter is out of range") S(SmartDashboardMissingKey
Attempted to reuse an allocated resource A timeout has been exceeded SmartDashboard data does not exist wpi::err::S (CommandIllegalUse, -50, "Illegal use of Command") S(CameraServerError
Attempted to reuse an allocated resource A timeout has been exceeded SmartDashboard data does not exist CameraServer error wpi::err::S (InvalidParameter, -100, "Invalid parameter value") S(AssertionFailure
 wpi::warn::S (BadJoystickIndex, 7, "Joystick index is out of range, should be 0-5") S(BadJoystickAxis

Macro Definition Documentation

◆ S [1/2]

#define S ( label,
offset,
message )
Value:
inline constexpr int label = offset;

◆ S [2/2]

#define S ( label,
offset,
message )
Value:
inline constexpr int label = offset;

◆ WPILIB_Assert

#define WPILIB_Assert ( condition)
Value:
WPILIB_AssertMessage(condition, #condition)
#define WPILIB_AssertMessage(condition, format,...)
Definition Errors.hpp:186

◆ WPILIB_AssertMessage

#define WPILIB_AssertMessage ( condition,
format,
... )
Value:
do { \
if (!(condition)) { \
throw ::wpi::MakeError(::wpi::err::AssertionFailure, __FILE__, __LINE__, \
__FUNCTION__, format __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)
FMT_INLINE auto format(locale_ref loc, format_string< T... > fmt, T &&... args) -> std::string
Definition format.h:4305

◆ WPILIB_CheckErrorStatus

#define WPILIB_CheckErrorStatus ( status,
format,
... )
Value:
do { \
if ((status) < 0) { \
throw ::wpi::MakeError(status, __FILE__, __LINE__, __FUNCTION__, \
format __VA_OPT__(, ) __VA_ARGS__); \
} else if ((status) > 0) { \
::wpi::ReportError(status, __FILE__, __LINE__, __FUNCTION__, \
format __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)

Checks a status code and depending on its value, either throws a RuntimeError exception, calls ReportError, or does nothing (if no error).

Parameters
[out]statuserror code
[in]formaterror message format

◆ WPILIB_MakeError

#define WPILIB_MakeError ( status,
format,
... )
Value:
::wpi::MakeError(status, __FILE__, __LINE__, __FUNCTION__, \
format __VA_OPT__(, ) __VA_ARGS__)
RuntimeError MakeError(int32_t status, const char *fileName, int lineNumber, const char *funcName, fmt::string_view format, Args &&... args)
Definition Errors.hpp:105

Makes a runtime error exception object.

This object should be thrown by the caller.

Parameters
[out]statuserror code
[in]formaterror message format
Returns
runtime error object

◆ WPILIB_ReportError

#define WPILIB_ReportError ( status,
format,
... )
Value:
do { \
if ((status) != 0) { \
::wpi::ReportError(status, __FILE__, __LINE__, __FUNCTION__, \
format __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)

Reports an error to the driver station (using HAL_SendError).

Parameters
[out]statuserror code
[in]formaterror message format

◆ WPILIB_ReportWarning

#define WPILIB_ReportWarning ( format,
... )
Value:
do { \
::wpi::ReportError(::wpi::warn::Warning, __FILE__, __LINE__, __FUNCTION__, \
format __VA_OPT__(, ) __VA_ARGS__); \
} while (0)

Reports a warning to the driver station (using HAL_SendError).

Parameters
[in]formaterror message format