WPILibC++ 2024.3.2
ErrorHandling.h File Reference
#include "wpi/Compiler.h"
#include <string>
#include <string_view>

Go to the source code of this file.

Classes

struct  wpi::ScopedFatalErrorHandler
 ScopedFatalErrorHandler - This is a simple helper class which just calls install_fatal_error_handler in its constructor and remove_fatal_error_handler in its destructor. More...
 

Namespaces

namespace  wpi
 

Macros

#define wpi_unreachable(msg)    ::wpi::wpi_unreachable_internal(msg, __FILE__, __LINE__)
 Marks that the current location is not supposed to be reachable. More...
 

Functions

void wpi::install_fatal_error_handler (fatal_error_handler_t handler, void *user_data=nullptr)
 install_fatal_error_handler - Installs a new error handler to be used whenever a serious (non-recoverable) error is encountered by LLVM. More...
 
void wpi::remove_fatal_error_handler ()
 Restores default error handling behaviour. More...
 
void wpi::report_fatal_error (const char *reason, bool gen_crash_diag=true)
 Reports a serious error, calling any installed error handler. More...
 
void wpi::report_fatal_error (const std::string &reason, bool gen_crash_diag=true)
 
void wpi::report_fatal_error (std::string_view reason, bool gen_crash_diag=true)
 
void wpi::install_bad_alloc_error_handler (fatal_error_handler_t handler, void *user_data=nullptr)
 Installs a new bad alloc error handler that should be used whenever a bad alloc error, e.g. More...
 
void wpi::remove_bad_alloc_error_handler ()
 Restores default bad alloc error handling behavior. More...
 
void wpi::install_out_of_memory_new_handler ()
 
void wpi::report_bad_alloc_error (const char *Reason, bool GenCrashDiag=true)
 Reports a bad alloc error, calling any user defined bad alloc error handler. More...
 
void wpi::wpi_unreachable_internal (const char *msg=nullptr, const char *file=nullptr, unsigned line=0)
 This function calls abort(), and prints the optional message to stderr. More...
 

Macro Definition Documentation

◆ wpi_unreachable

#define wpi_unreachable (   msg)     ::wpi::wpi_unreachable_internal(msg, __FILE__, __LINE__)

Marks that the current location is not supposed to be reachable.

In !NDEBUG builds, prints the message and location info to stderr. In NDEBUG builds, if the platform does not support a builtin unreachable then we call an internal LLVM runtime function. Otherwise the behavior is controlled by the CMake flag -DLLVM_UNREACHABLE_OPTIMIZE

  • When "ON" (default) wpi_unreachable() becomes an optimizer hint that the current location is not supposed to be reachable: the hint turns such code path into undefined behavior. On compilers that don't support such hints, prints a reduced message instead and aborts the program.
  • When "OFF", a builtin_trap is emitted instead of an Use this instead of assert(0). It conveys intent more clearly, suppresses diagnostics for unreachable code paths, and allows compilers to omit unnecessary code.