WPILibC++ 2023.4.3
Errors.h File Reference
#include <stdint.h>
#include <memory>
#include <stdexcept>
#include <string>
#include <fmt/format.h>
#include "frc/WPIErrors.mac"
#include "frc/WPIWarnings.mac"

Go to the source code of this file.

Classes

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

Namespaces

namespace  frc
 
namespace  frc::err
 
namespace  frc::warn
 

Macros

#define S(label, offset, message)   inline constexpr int label = offset;
 
#define S(label, offset, message)   inline constexpr int label = offset;
 
#define FRC_ReportError(status, format, ...)
 Reports an error to the driver station (using HAL_SendError). More...
 
#define FRC_MakeError(status, format, ...)
 Makes a runtime error exception object. More...
 
#define FRC_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). More...
 
#define FRC_AssertMessage(condition, format, ...)
 
#define FRC_Assert(condition)   FRC_AssertMessage(condition, #condition)
 

Functions

const char * frc::GetErrorMessage (int32_t *code)
 Gets error message string for an error code. More...
 
void frc::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). More...
 
template<typename... Args>
void frc::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). More...
 
RuntimeError frc::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. More...
 
template<typename... Args>
RuntimeError frc::MakeError (int32_t status, const char *fileName, int lineNumber, const char *funcName, fmt::string_view format, Args &&... args)
 

Macro Definition Documentation

◆ FRC_Assert

#define FRC_Assert (   condition)    FRC_AssertMessage(condition, #condition)

◆ FRC_AssertMessage

#define FRC_AssertMessage (   condition,
  format,
  ... 
)
Value:
do { \
if (!(condition)) { \
throw ::frc::MakeError(err::AssertionFailure, __FILE__, __LINE__, \
__FUNCTION__, \
FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)
#define FMT_STRING(s)
\rst Constructs a compile-time format string from a string literal s.
Definition: format.h:1772
RuntimeError MakeError(int32_t status, const char *fileName, int lineNumber, const char *funcName, fmt::string_view format, Args &&... args)
Definition: Errors.h:104
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:87

◆ FRC_CheckErrorStatus

#define FRC_CheckErrorStatus (   status,
  format,
  ... 
)
Value:
do { \
if ((status) < 0) { \
throw ::frc::MakeError(status, __FILE__, __LINE__, __FUNCTION__, \
FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__); \
} else if ((status) > 0) { \
::frc::ReportError(status, __FILE__, __LINE__, __FUNCTION__, \
FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)
void 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).
Definition: Errors.h:78
GHC_FS_API file_status status(const path &p, std::error_code &ec) noexcept
Definition: filesystem.hpp:4892

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

◆ FRC_MakeError

#define FRC_MakeError (   status,
  format,
  ... 
)
Value:
::frc::MakeError(status, __FILE__, __LINE__, __FUNCTION__, \
FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__)

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

◆ FRC_ReportError

#define FRC_ReportError (   status,
  format,
  ... 
)
Value:
do { \
if ((status) != 0) { \
::frc::ReportError(status, __FILE__, __LINE__, __FUNCTION__, \
FMT_STRING(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

◆ S [1/2]

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

◆ S [2/2]

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