32#ifndef ETL_ERROR_HANDLER_INCLUDED
33#define ETL_ERROR_HANDLER_INCLUDED
46#if defined(ETL_LOG_ERRORS) || defined(ETL_IN_UNIT_TEST)
60 struct free_function :
public etl::function<void, const etl::exception&>
63 :
etl::function<void, const
etl::exception&>(p_function_)
71 template <
typename TObject>
72 struct member_function :
public etl::function<TObject, const etl::exception&>
74 member_function(TObject& object_,
void(TObject::*p_function_)(const
etl::exception&))
75 :
etl::function<TObject, const
etl::exception&>(object_, p_function_)
84 static void set_callback(ifunction<const etl::exception&>& f)
86 create((
void*)(&f), ifunction_stub);
92 template <
void(*Method)(const etl::exception&)>
93 static void set_callback()
95 create(ETL_NULLPTR, function_stub<Method>);
101 template <
typename T,
void(T::* Method)(const etl::exception&)>
102 static void set_callback(T& instance)
104 create((
void*)(&instance), method_stub<T, Method>);
110 template <
typename T,
void(T::* Method)(const etl::exception&) const>
111 static void set_callback(
const T& instance)
113 create((
void*)(&instance), const_method_stub<T, Method>);
119 template <
typename T, T& Instance,
void(T::* Method)(const etl::exception&)>
120 static void set_callback()
122 create(method_instance_stub<T, Instance, Method>);
128 template <
typename T, T const& Instance,
void(T::* Method)(const etl::exception&) const>
129 static void set_callback()
131 create(const_method_instance_stub<T, Instance, Method>);
140 invocation_element& invocation = get_invocation_element();
142 if (invocation.stub != ETL_NULLPTR)
144 (*invocation.stub)(invocation.object, e);
155 struct invocation_element
159 : object(ETL_NULLPTR)
172 static invocation_element& get_invocation_element()
174 static invocation_element invocation;
182 static void create(
void*
object, stub_type stub)
184 invocation_element& invocation = get_invocation_element();
186 invocation.object = object;
187 invocation.stub = stub;
193 static void create(stub_type stub)
195 invocation_element& invocation = get_invocation_element();
197 invocation.object = ETL_NULLPTR;
198 invocation.stub = stub;
204 template <
typename T,
void(T::* Method)(const etl::exception&)>
207 T* p =
static_cast<T*
>(object);
208 return (p->*Method)(e);
214 template <
typename T,
void(T::* Method)(const etl::exception&) const>
215 static void const_method_stub(
void*
object,
const etl::exception& e)
217 T*
const p =
static_cast<T*
>(object);
218 return (p->*Method)(e);
224 template <
typename T, T& Instance,
void(T::* Method)(const etl::exception&)>
227 return (Instance.*Method)(e);
233 template <
typename T, const T& Instance,
void(T::* Method)(const etl::exception&) const>
234 static void const_method_instance_stub(
void*,
const etl::exception& e)
236 (Instance.*Method)(e);
242 template <
void(*Method)(const etl::exception&)>
258#elif defined(ETL_USE_ASSERT_FUNCTION)
261 namespace private_error_handler
269 static assert_function_ptr_t assert_function_ptr;
285 void set_assert_function(etl::private_error_handler::assert_function_ptr_t afptr)
287 etl::private_error_handler::assert_handler<0>::assert_function_ptr = afptr;
303#if defined(ETL_NO_CHECKS)
304 #define ETL_ASSERT(b, e) ETL_DO_NOTHING
305 #define ETL_ASSERT_OR_RETURN(b, e) ETL_DO_NOTHING
306 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) ETL_DO_NOTHING
308 #define ETL_ASSERT_FAIL(e) ETL_DO_NOTHING
309 #define ETL_ASSERT_FAIL_AND_RETURN(e) ETL_DO_NOTHING
310 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) ETL_DO_NOTHING
311#elif defined(ETL_USE_ASSERT_FUNCTION)
312 #define ETL_ASSERT(b, e) {if(!(b)) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e));}}
313 #define ETL_ASSERT_OR_RETURN(b, e) {if(!(b)) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return;}}
314 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if(!(b)) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return (v);}}
316 #define ETL_ASSERT_FAIL(e) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e));}
317 #define ETL_ASSERT_FAIL_AND_RETURN(e) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return;}
318 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return (v);}
319#elif ETL_USING_EXCEPTIONS
320 #if defined(ETL_LOG_ERRORS)
321 #define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e));}}
322 #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e)); return;}}
323 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) {etl::error_handler::error((e)); throw((e)); return(v);}}
325 #define ETL_ASSERT_FAIL(e) {etl::error_handler::error((e)); throw((e));}
326 #define ETL_ASSERT_FAIL_AND_RETURN(e) {etl::error_handler::error((e)); throw((e)); return;}
327 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::error_handler::error((e)); throw((e)); return(v);}
329 #define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}}
330 #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) {throw((e));}}
331 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) {throw((e));}}
333 #define ETL_ASSERT_FAIL(e) {throw((e));}
334 #define ETL_ASSERT_FAIL_AND_RETURN(e) {throw((e));}
335 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {throw((e));}
338 #if defined(ETL_LOG_ERRORS)
339 #define ETL_ASSERT(b, e) {if(!(b)) {etl::error_handler::error((e));}}
340 #define ETL_ASSERT_OR_RETURN(b, e) {if(!(b)) {etl::error_handler::error((e)); return;}}
341 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if(!(b)) {etl::error_handler::error((e)); return (v);}}
343 #define ETL_ASSERT_FAIL(e) {etl::error_handler::error((e));}
344 #define ETL_ASSERT_FAIL_AND_RETURN(e) {etl::error_handler::error((e)); return;}
345 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::error_handler::error((e)); return (v);}
347 #if ETL_IS_DEBUG_BUILD
348 #define ETL_ASSERT(b, e) assert((b))
349 #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) {assert(false); return;}}
350 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) {assert(false); return(v);}}
352 #define ETL_ASSERT_FAIL(e) assert(false)
353 #define ETL_ASSERT_FAIL_AND_RETURN(e) {assert(false); return;}
354 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {assert(false); return(v);}
356 #define ETL_ASSERT(b, e)
357 #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) return;}
358 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) return(v);}
360 #define ETL_ASSERT_FAIL(e)
361 #define ETL_ASSERT_FAIL_AND_RETURN(e) {return;}
362 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {return(v);}
367#if defined(ETL_VERBOSE_ERRORS)
368 #define ETL_ERROR(e) (e(__FILE__, __LINE__))
369 #define ETL_ERROR_WITH_VALUE(e, v) (e(__FILE__, __LINE__, (v)))
371 #define ETL_ERROR(e) (e("", __LINE__))
372 #define ETL_ERROR_WITH_VALUE(e, v) (e("", __LINE__, (v)))
375#if defined(ETL_VERBOSE_ERRORS)
376 #define ETL_ERROR_TEXT(verbose_text, terse_text) (verbose_text)
378 #define ETL_ERROR_TEXT(verbose_text, terse_text) (terse_text)
Definition exception.h:47
bitset_ext
Definition absolute.h:38
T * create(Args &&... args)
Creates the object from a type. Variadic parameter constructor.
Definition variant_pool_generator.h:348
pair holds two objects of arbitrary type
Definition utility.h:164
ETL_CONSTEXPR pair()
Default constructor.
Definition utility.h:176