[C] Changed errors descriptions

This commit is contained in:
seleznevae 2020-02-23 11:54:59 +03:00
parent d91c7ce9d1
commit cd11dfd7de
7 changed files with 47 additions and 35 deletions

View File

@ -3618,18 +3618,18 @@ const char *ft_strerror(int error_code)
{
switch (error_code) {
case FT_MEMORY_ERROR:
return "Libfort error (out of memory)";
return "Out of memory";
case FT_GEN_ERROR:
return "Libfort error (general error)";
return "General error";
case FT_EINVAL:
return "Libfort error (invalid argument)";
return "Invalid argument";
case FT_INTERN_ERROR:
return "Libfort error (internal logic error)";
return "Internal libfort error";
default:
if (error_code < 0)
return "Libfort unknown error";
return "Unknown error code";
else
return "Libfort success";
return "Success";
}
}

View File

@ -91,11 +91,18 @@ SOFTWARE.
/**
* Libfort internal logic error.
*
* Usually such errors mean that something is wrong in
* libfort internal logic and in most of cases cause of
* these errors is a library bug.
*/
#define FT_INTERN_ERROR -3
/**
* General error.
*
* Different errors that do not belong to the group of errors
* mentioned above.
*/
#define FT_GEN_ERROR -4

View File

@ -391,9 +391,8 @@ public:
: property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this),
table_(ft_create_table())
{
if (table_ == NULL)
throw std::runtime_error("Libfort runtime error");
throw std::bad_alloc();
}
/**
@ -413,7 +412,7 @@ public:
if (tbl.table_) {
ft_table_t *table_copy = ft_copy_table(tbl.table_);
if (table_copy == NULL)
throw std::runtime_error("Libfort runtime error");
throw std::runtime_error("Error during table copy");
stream_.str(std::string());
if (tbl.stream_.tellp() >= 0) {
@ -447,7 +446,7 @@ public:
if (tbl.table_) {
ft_table_t *table_copy = ft_copy_table(tbl.table_);
if (table_copy == NULL)
throw std::runtime_error("Libfort runtime error");
throw std::runtime_error("Error during table copy");
stream_.str(std::string());
if (tbl.stream_.tellp() >= 0) {
@ -491,7 +490,7 @@ public:
{
const char *str = c_str();
if (str == NULL)
throw std::runtime_error("Libfort runtime error");
throw std::runtime_error("Error during table to string conversion");
return str;
}

View File

@ -91,11 +91,18 @@ SOFTWARE.
/**
* Libfort internal logic error.
*
* Usually such errors mean that something is wrong in
* libfort internal logic and in most of cases cause of
* these errors is a library bug.
*/
#define FT_INTERN_ERROR -3
/**
* General error.
*
* Different errors that do not belong to the group of errors
* mentioned above.
*/
#define FT_GEN_ERROR -4

View File

@ -391,9 +391,8 @@ public:
: property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this),
table_(ft_create_table())
{
if (table_ == NULL)
throw std::runtime_error("Libfort runtime error");
throw std::bad_alloc();
}
/**
@ -413,7 +412,7 @@ public:
if (tbl.table_) {
ft_table_t *table_copy = ft_copy_table(tbl.table_);
if (table_copy == NULL)
throw std::runtime_error("Libfort runtime error");
throw std::runtime_error("Error during table copy");
stream_.str(std::string());
if (tbl.stream_.tellp() >= 0) {
@ -447,7 +446,7 @@ public:
if (tbl.table_) {
ft_table_t *table_copy = ft_copy_table(tbl.table_);
if (table_copy == NULL)
throw std::runtime_error("Libfort runtime error");
throw std::runtime_error("Error during table copy");
stream_.str(std::string());
if (tbl.stream_.tellp() >= 0) {
@ -491,7 +490,7 @@ public:
{
const char *str = c_str();
if (str == NULL)
throw std::runtime_error("Libfort runtime error");
throw std::runtime_error("Error during table to string conversion");
return str;
}

View File

@ -1022,18 +1022,18 @@ const char *ft_strerror(int error_code)
{
switch (error_code) {
case FT_MEMORY_ERROR:
return "Libfort error (out of memory)";
return "Out of memory";
case FT_GEN_ERROR:
return "Libfort error (general error)";
return "General error";
case FT_EINVAL:
return "Libfort error (invalid argument)";
return "Invalid argument";
case FT_INTERN_ERROR:
return "Libfort error (internal logic error)";
return "Internal libfort error";
default:
if (error_code < 0)
return "Libfort unknown error";
return "Unknown error code";
else
return "Libfort success";
return "Success";
}
}

View File

@ -6,23 +6,23 @@ void test_error_codes(void)
{
// Nonnegative code is success
{
assert_str_equal(ft_strerror(FT_SUCCESS), "Libfort success");
assert_str_equal(ft_strerror(0), "Libfort success");
assert_str_equal(ft_strerror(1), "Libfort success");
assert_str_equal(ft_strerror(2), "Libfort success");
assert_str_equal(ft_strerror(42), "Libfort success");
assert_str_equal(ft_strerror(INT_MAX), "Libfort success");
assert_str_equal(ft_strerror(FT_SUCCESS), "Success");
assert_str_equal(ft_strerror(0), "Success");
assert_str_equal(ft_strerror(1), "Success");
assert_str_equal(ft_strerror(2), "Success");
assert_str_equal(ft_strerror(42), "Success");
assert_str_equal(ft_strerror(INT_MAX), "Success");
}
// Error codes
{
assert_str_equal(ft_strerror(FT_MEMORY_ERROR), "Libfort error (out of memory)");
assert_str_equal(ft_strerror(FT_EINVAL), "Libfort error (invalid argument)");
assert_str_equal(ft_strerror(FT_INTERN_ERROR), "Libfort error (internal logic error)");
assert_str_equal(ft_strerror(FT_GEN_ERROR), "Libfort error (general error)");
assert_str_equal(ft_strerror(FT_MEMORY_ERROR), "Out of memory");
assert_str_equal(ft_strerror(FT_EINVAL), "Invalid argument");
assert_str_equal(ft_strerror(FT_INTERN_ERROR), "Internal libfort error");
assert_str_equal(ft_strerror(FT_GEN_ERROR), "General error");
assert_str_equal(ft_strerror(-42), "Libfort unknown error");
assert_str_equal(ft_strerror(-666), "Libfort unknown error");
assert_str_equal(ft_strerror(-INT_MAX), "Libfort unknown error");
assert_str_equal(ft_strerror(-42), "Unknown error code");
assert_str_equal(ft_strerror(-666), "Unknown error code");
assert_str_equal(ft_strerror(-INT_MAX), "Unknown error code");
}
}