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&)>
270#if defined(ETL_NO_CHECKS)
271 #define ETL_ASSERT(b, e)
272 #define ETL_ASSERT_OR_RETURN(b, e)
273 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v)
275 #define ETL_ASSERT_FAIL(e)
276 #define ETL_ASSERT_FAIL_AND_RETURN(e)
277 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v)
278#elif ETL_USING_EXCEPTIONS
279 #if defined(ETL_LOG_ERRORS)
280 #define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e));}}
281 #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e)); return;}}
282 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) {etl::error_handler::error((e)); throw((e)); return(v);}}
284 #define ETL_ASSERT_FAIL(e) {etl::error_handler::error((e)); throw((e));}
285 #define ETL_ASSERT_FAIL_AND_RETURN(e) {etl::error_handler::error((e)); throw((e)); return;}
286 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::error_handler::error((e)); throw((e)); return(v);}
288 #define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}}
289 #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) {throw((e));}}
290 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) {throw((e));}}
292 #define ETL_ASSERT_FAIL(e) {throw((e));}
293 #define ETL_ASSERT_FAIL_AND_RETURN(e) {throw((e));}
294 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {throw((e));}
298 #if defined(ETL_LOG_ERRORS)
299 #define ETL_ASSERT(b, e) {if(!(b)) {etl::error_handler::error((e));}}
300 #define ETL_ASSERT_OR_RETURN(b, e) {if(!(b)) {etl::error_handler::error((e)); return;}}
301 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if(!(b)) {etl::error_handler::error((e)); return (v);}}
303 #define ETL_ASSERT_FAIL(e) {etl::error_handler::error((e));}
304 #define ETL_ASSERT_FAIL_AND_RETURN(e) {etl::error_handler::error((e)); return;}
305 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::error_handler::error((e)); return (v);}
307 #if ETL_IS_DEBUG_BUILD
308 #define ETL_ASSERT(b, e) assert((b))
309 #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) {assert(false); return;}}
310 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) {assert(false); return(v);}}
312 #define ETL_ASSERT_FAIL(e) assert(false)
313 #define ETL_ASSERT_FAIL_AND_RETURN(e) {assert(false); return;}
314 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {assert(false); return(v);}
316 #define ETL_ASSERT(b, e)
317 #define ETL_ASSERT_OR_RETURN(b, e) {if (!(b)) return;}
318 #define ETL_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) return(v);}
320 #define ETL_ASSERT_FAIL(e)
321 #define ETL_ASSERT_FAIL_AND_RETURN(e) {return;}
322 #define ETL_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {return(v);}
327#if defined(ETL_VERBOSE_ERRORS)
328 #define ETL_ERROR(e) (e(__FILE__, __LINE__))
329 #define ETL_ERROR_WITH_VALUE(e, v) (e(__FILE__, __LINE__, (v)))
331 #define ETL_ERROR(e) (e("", __LINE__))
332 #define ETL_ERROR_WITH_VALUE(e, v) (e("", __LINE__, (v)))
335#if defined(ETL_VERBOSE_ERRORS)
336 #define ETL_ERROR_TEXT(verbose_text, terse_text) (verbose_text)
338 #define ETL_ERROR_TEXT(verbose_text, terse_text) (terse_text)
Definition: exception.h:47
Definition: function.h:94
Definition: function.h:54
bitset_ext
Definition: absolute.h:38
T * create(Args &&... args)
Creates the object from a type. Variadic parameter constructor.
Definition: variant_pool_generator.h:234