mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Spare more Resources for non-verbose Errors (#1214)
* Spare more Resources for non-verbose Errors At the moment we only remove the __FILE__ in case ETL_VERBOSE_ERRORS is not set. However, we also want to remove the error text which can consume quite some resources and without the file name the line number is also not very useful. * Introduce separate ETL_MINIMAL_ERRORS to keep backwards compatability To not break runtime backwards compatability, instead of removing the text in case of ETL_VERBOSE_ERRORS not defined, we introduce a second flag ETL_MINIMAL_ERRORS which is mutually exclusive. The semantic is as follows: - ETL_VERBOSE_ERRORS: We use verbose text, file names and line numbers. - ETL_MINIMAL_ERRORS: We do not use anything. - ETL_VERBOSE_ERRORS and ETL_MINIMAL_ERRORS: Issue an error. - non defined: We use terse text without file names nor line numbers. --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
This commit is contained in:
parent
8d2f91de9f
commit
b2a4b4410c
@ -397,15 +397,23 @@ namespace etl
|
||||
|
||||
//*************************************
|
||||
#if defined(ETL_VERBOSE_ERRORS)
|
||||
#define ETL_ERROR(e) (e(__FILE__, __LINE__)) // Make an exception with the file name and line number.
|
||||
#define ETL_ERROR_WITH_VALUE(e, v) (e(__FILE__, __LINE__, (v))) // Make an exception with the file name, line number and value.
|
||||
#define ETL_ERROR_TEXT(verbose_text, terse_text) (verbose_text) // Use the verbose text.
|
||||
#define ETL_ERROR_GENERIC(text) (etl::exception((text),__FILE__, __LINE__)) // Make a generic exception with a message, file name and line number.
|
||||
// include everything, file name, line number, verbose text
|
||||
#define ETL_ERROR(e) (e(__FILE__, __LINE__))
|
||||
#define ETL_ERROR_WITH_VALUE(e, v) (e(__FILE__, __LINE__, (v)))
|
||||
#define ETL_ERROR_TEXT(verbose_text, terse_text) (verbose_text)
|
||||
#define ETL_ERROR_GENERIC(text) (etl::exception((text), __FILE__, __LINE__))
|
||||
#elif defined(ETL_MINIMAL_ERRORS)
|
||||
// include nothing, no file name, no line number, no text
|
||||
#define ETL_ERROR(e) (e("", -1))
|
||||
#define ETL_ERROR_WITH_VALUE(e, v) (e("", -1, (v)))
|
||||
#define ETL_ERROR_TEXT(verbose_text, terse_text) ("")
|
||||
#define ETL_ERROR_GENERIC(text) (etl::exception("", "", -1))
|
||||
#else
|
||||
#define ETL_ERROR(e) (e("", __LINE__)) // Make an exception with the line number.
|
||||
#define ETL_ERROR_WITH_VALUE(e, v) (e("", __LINE__, (v))) // Make an exception with the file name, line number and value.
|
||||
#define ETL_ERROR_TEXT(verbose_text, terse_text) (terse_text) // Use the terse text.
|
||||
#define ETL_ERROR_GENERIC(text) (etl::exception((text),"", __LINE__)) // Make a generic exception with a message and line number.
|
||||
// include only terse text, no file name, no line number
|
||||
#define ETL_ERROR(e) (e("", -1))
|
||||
#define ETL_ERROR_WITH_VALUE(e, v) (e("", -1, (v)))
|
||||
#define ETL_ERROR_TEXT(verbose_text, terse_text) (terse_text)
|
||||
#define ETL_ERROR_GENERIC(text) (etl::exception((text),"", -1))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -60,26 +60,27 @@ namespace etl
|
||||
|
||||
typedef const char* string_type;
|
||||
typedef int numeric_type;
|
||||
|
||||
#if defined(ETL_VERBOSE_ERRORS)
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
ETL_EXCEPTION_CONSTEXPR
|
||||
#if defined(ETL_VERBOSE_ERRORS)
|
||||
ETL_CONSTEXPR
|
||||
exception(string_type reason_, string_type file_, numeric_type line_)
|
||||
: reason_text(reason_),
|
||||
file_text(file_),
|
||||
line(line_)
|
||||
{
|
||||
}
|
||||
#elif defined(ETL_MINIMAL_ERRORS)
|
||||
ETL_CONSTEXPR
|
||||
exception(string_type /*reason_*/, string_type /*file_*/, numeric_type /*line_*/)
|
||||
{
|
||||
}
|
||||
#else
|
||||
//*************************************************************************
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
ETL_EXCEPTION_CONSTEXPR
|
||||
exception(string_type reason_, string_type /*file_*/, numeric_type line_)
|
||||
: reason_text(reason_),
|
||||
line(line_)
|
||||
ETL_CONSTEXPR
|
||||
exception(string_type reason_, string_type /*file_*/, numeric_type /*line_*/)
|
||||
: reason_text(reason_)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
@ -94,7 +95,11 @@ namespace etl
|
||||
override
|
||||
#endif
|
||||
{
|
||||
#if !defined(ETL_MINIMAL_ERRORS)
|
||||
return reason_text;
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -119,16 +124,23 @@ namespace etl
|
||||
ETL_CONSTEXPR
|
||||
numeric_type line_number() const
|
||||
{
|
||||
#if defined(ETL_VERBOSE_ERRORS)
|
||||
return line;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
string_type reason_text; ///< The reason for the exception.
|
||||
#if !defined(ETL_MINIMAL_ERRORS)
|
||||
string_type reason_text; ///< The reason for the exception.
|
||||
#endif
|
||||
|
||||
#if defined(ETL_VERBOSE_ERRORS)
|
||||
string_type file_text; ///< The file for the exception.
|
||||
#endif
|
||||
numeric_type line; ///< The line for the exception.
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -83,6 +83,12 @@ SOFTWARE.
|
||||
#define ETL_IS_DEBUG_BUILD 0
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Do a validity check for error settings, only one is allowed.
|
||||
#if defined(ETL_VERBOSE_ERRORS) && defined(ETL_MINIMAL_ERRORS)
|
||||
#error "ETL_VERBOSE_ERRORS and ETL_MINIMAL_ERRORS are mutually exclusive"
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Helper macros, so we don't have to use double negatives.
|
||||
// The ETL will use the STL, unless ETL_NO_STL is defined.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user