WPILibC++  2020.3.2
ErrorHandling.h
1 //===- llvm/Support/ErrorHandling.h - Fatal error handling ------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines an API used to indicate fatal error conditions. Non-fatal
11 // errors (most of them) should be handled through LLVMContext.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef WPIUTIL_WPI_ERRORHANDLING_H
16 #define WPIUTIL_WPI_ERRORHANDLING_H
17 
18 #include "wpi/Compiler.h"
19 #include <string>
20 
21 namespace wpi {
22 class StringRef;
23  class Twine;
24 
26  typedef void (*fatal_error_handler_t)(void *user_data,
27  const std::string& reason,
28  bool gen_crash_diag);
29 
47  void *user_data = nullptr);
48 
51 
57  void *user_data = nullptr) {
58  install_fatal_error_handler(handler, user_data);
59  }
60 
62  };
63 
72 LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason,
73  bool gen_crash_diag = true);
74 LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const std::string &reason,
75  bool gen_crash_diag = true);
76 LLVM_ATTRIBUTE_NORETURN void report_fatal_error(StringRef reason,
77  bool gen_crash_diag = true);
78 LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const Twine &reason,
79  bool gen_crash_diag = true);
80 
98  void *user_data = nullptr);
99 
102 
103 void install_out_of_memory_new_handler();
104 
117 void report_bad_alloc_error(const char *Reason, bool GenCrashDiag = true);
118 
122 LLVM_ATTRIBUTE_NORETURN void
123 wpi_unreachable_internal(const char *msg = nullptr, const char *file = nullptr,
124  unsigned line = 0);
125 }
126 
135 #ifndef NDEBUG
136 #define wpi_unreachable(msg) \
137  ::wpi::wpi_unreachable_internal(msg, __FILE__, __LINE__)
138 #elif defined(LLVM_BUILTIN_UNREACHABLE)
139 #define wpi_unreachable(msg) LLVM_BUILTIN_UNREACHABLE
140 #else
141 #define wpi_unreachable(msg) ::wpi::wpi_unreachable_internal()
142 #endif
143 
144 #endif
wpi::report_fatal_error
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
wpi::fatal_error_handler_t
void(* fatal_error_handler_t)(void *user_data, const std::string &reason, bool gen_crash_diag)
An error handler callback.
Definition: ErrorHandling.h:26
wpi::wpi_unreachable_internal
LLVM_ATTRIBUTE_NORETURN void 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.
wpi::install_fatal_error_handler
void 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-recover...
wpi
WPILib C++ utilities (wpiutil) namespace.
Definition: EventLoopRunner.h:17
wpi::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
wpi::ScopedFatalErrorHandler
ScopedFatalErrorHandler - This is a simple helper class which just calls install_fatal_error_handler ...
Definition: ErrorHandling.h:55
wpi::report_bad_alloc_error
void report_bad_alloc_error(const char *Reason, bool GenCrashDiag=true)
Reports a bad alloc error, calling any user defined bad alloc error handler.
wpi::install_bad_alloc_error_handler
void 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,...
wpi::remove_bad_alloc_error_handler
void remove_bad_alloc_error_handler()
Restores default bad alloc error handling behavior.
wpi::remove_fatal_error_handler
void remove_fatal_error_handler()
Restores default error handling behaviour.
wpi::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:85