29 explicit Error(
const char *msg);
30 explicit Error(
const std::string &msg);
39 virtual const
char *what() const noexcept;
51 static constexpr auto verbose_name =
"Runtime error";
52 static constexpr int verbose_debug_level = 1;
61 static constexpr auto verbose_name =
"User error";
62 static constexpr int verbose_debug_level = 1;
72 static constexpr auto verbose_name =
"Internal error";
73 static constexpr int verbose_debug_level = 0;
89 virtual void warning(
const char *msg) = 0;
90 [[noreturn]]
virtual void error(
const char *msg) = 0;
131 std::ostringstream msg{};
132 bool finalized{
false};
134 std::unique_ptr<Contents> contents = std::make_unique<Contents>();
140 return *
static_cast<T *
>(
this);
144 return !contents->finalized;
153 if (!contents->msg.str().empty() && contents->msg.str().back() !=
'\n') {
154 contents->msg <<
"\n";
156 contents->finalized =
true;
157 return contents->msg.str();
160 T &
init(
const char *file,
const char *function,
const int line,
const char *condition_string) {
162 contents->msg << T::verbose_name <<
" at " << file <<
":" << line <<
'\n';
163 if (condition_string) {
164 contents->msg <<
"Condition failed: " << condition_string <<
'\n';
167 return *
static_cast<T *
>(
this);
171template<
typename Exception>
173 static constexpr auto verbose_name = Exception::verbose_name;
174 static constexpr int verbose_debug_level = Exception::verbose_debug_level;
176 ErrorReport &
init(
const char *file,
const char *function,
const int line,
const char *condition_string) {
180 [[noreturn]]
void issue() noexcept(false) {
186 static constexpr auto verbose_name =
"Warning";
187 static constexpr int verbose_debug_level = 1;
189 WarningReport &
init(
const char *file,
const char *function,
const int line,
const char *condition_string) {
190 return ReportBase::init(file, function, line, condition_string) <<
"Warning: ";
212#define _halide_error_impl(type) \
213 for (Halide::Internal::ErrorReport<type> _err; 1; _err.issue()) \
214 _err.init(__FILE__, __FUNCTION__, __LINE__, nullptr)
216#define _halide_assert_impl(condition, type) \
218 for (Halide::Internal::ErrorReport<type> _err; 1; _err.issue()) \
219 _err.init(__FILE__, __FUNCTION__, __LINE__, #condition)
221#define _halide_user_warning \
222 for (Halide::Internal::WarningReport _err; _err; _err.issue()) \
223 _err.init(__FILE__, __FUNCTION__, __LINE__, nullptr)
226#define user_warning _halide_user_warning
228#define user_error _halide_error_impl(Halide::CompileError)
229#define internal_error _halide_error_impl(Halide::InternalError)
230#define halide_runtime_error _halide_error_impl(Halide::RuntimeError)
232#define internal_assert(c) _halide_assert_impl(c, Halide::InternalError)
233#define user_assert(c) _halide_assert_impl(c, Halide::CompileError)
239#define _halide_user_error _halide_error_impl(Halide::CompileError)
240#define _halide_internal_error _halide_error_impl(Halide::InternalError)
241#define _halide_runtime_error _halide_error_impl(Halide::RuntimeError)
242#define _halide_internal_assert(c) _halide_assert_impl(c, Halide::InternalError)
243#define _halide_user_assert(c) _halide_assert_impl(c, Halide::CompileError)
Defines functions for debug logging during code generation.
This file declares the routines used by Halide internally in its runtime.
#define HALIDE_EXPORT_SYMBOL
#define HALIDE_ALWAYS_INLINE
CompileTimeErrorReporter is used at compile time (not runtime) when an error or warning is generated ...
virtual void warning(const char *msg)=0
virtual void error(const char *msg)=0
virtual ~CompileTimeErrorReporter()=default
std::string finalize_message()
T & init(const char *file, const char *function, const int line, const char *condition_string)
HALIDE_ALWAYS_INLINE T & operator<<(const S &x)
void throw_error(const RuntimeError &e)
If a custom error reporter is configured, notifies the reporter by calling its error() function with ...
void issue_warning(const char *warning)
If a custom error reporter is configured, notifies the reporter by calling its warning() function.
HALIDE_EXPORT_SYMBOL void unhandled_exception_handler()
bool debug_is_active_impl(int verbosity, const char *file, const char *function, int line)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
bool exceptions_enabled()
Query whether Halide was compiled with exceptions.
void set_custom_compile_time_error_reporter(CompileTimeErrorReporter *error_reporter)
The default error reporter logs to stderr, then throws an exception (if HALIDE_WITH_EXCEPTIONS) or ca...
An error that occurs while compiling a Halide pipeline that Halide attributes to a user error.
CompileError(const char *msg)
CompileError(const std::string &msg)
A base class for Halide errors.
Error(const std::string &msg)
Error & operator=(const Error &)
void issue() noexcept(false)
ErrorReport & init(const char *file, const char *function, const int line, const char *condition_string)
WarningReport & init(const char *file, const char *function, const int line, const char *condition_string)
An error that occurs while compiling a Halide pipeline that Halide attributes to an internal compiler...
InternalError(const std::string &msg)
InternalError(const char *msg)
An error that occurs while running a JIT-compiled Halide pipeline.
RuntimeError(const char *msg)
RuntimeError(const std::string &msg)