WPILibC++ 2024.1.1-beta-4
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:1912
RuntimeError MakeError(int32_t status, const char *fileName, int lineNumber, const char *funcName, fmt::string_view format, Args &&... args)
Definition: Errors.h:105
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
\rst Formats arguments and returns the result as a string using ANSI escape sequences to specify text...
Definition: color.h:534

◆ 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

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;