diff --git a/README.md b/README.md index 1a49e80e..b63980ee 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ Other headers offering other functionality are: * [m-bitset.h](#m-bitset): header for creating bit set (or "packed array of bool"), * [m-algo.h](#m-algo): header for providing various generic algorithms to the previous containers. * [m-funcobj.h](#m-funcobj): header for creating function object (used by algorithm generation). -* [m-try.h][#m-try): header for handling errors as exceptions, +* [m-try.h](#m-try): header for handling errors as exceptions, * [m-mempool.h](#m-mempool): header for creating specialized & fast memory allocator. * [m-worker.h](#m-worker): header for providing an easy pool of workers on separated threads to handle work orders, used for parallelism tasks. * [m-serial-json.h](#m-serial-json): header for importing / exporting the containers in [JSON format](https://en.wikipedia.org/wiki/JSON). @@ -7750,8 +7750,10 @@ This is the exception type. It is composed of the following fields: * error\_code: The error code. It is used to identify the error that are raised the exception. * line: The line number where the error was detected. * filename: The filename (CSTR) where the error was detected. -* n: Number of entries in 'error' table -* error: an array of M\_USE\_MAX\_EXCEPTION elements. +* n: Number of entries in 'data' table +* data: an array of M\_USE\_MAX\_EXCEPTION elements. + +You can access the fields of the type directly. #### M\_TRY(name) @@ -7775,6 +7777,7 @@ Throw the exception associated to the error\_code. error\_code shall be a positive integer constant. Additional arguments are used to fill in the error field of m\_exception\_s that is used to identify the cause of the exception. +The line and filename fields of the exception are filled automatically by the macro. ### M-MEMPOOL diff --git a/m-try.h b/m-try.h index a9d9fc2a..229b7528 100644 --- a/m-try.h +++ b/m-try.h @@ -123,7 +123,7 @@ struct m_exception_s { unsigned short line; // Line number where the error was detected unsigned short n; // Number of entries in 'error' table const char *filename; // filename where the error was detected - intptr_t error[M_USE_MAX_EXCEPTION]; // Error specific data + intptr_t data[M_USE_MAX_EXCEPTION]; // Specific data of the exception #ifdef __cplusplus m_exception_s *operator->() { return this; } #endif diff --git a/tests/test-mtry.c b/tests/test-mtry.c index 9d4b2bab..d625a7f7 100644 --- a/tests/test-mtry.c +++ b/tests/test-mtry.c @@ -32,7 +32,7 @@ static void test_throw(void) M_THROW(67, 56); } M_CATCH(protect, 67) { assert(protect->n == 1); - M_THROW(M_ERROR_MEMORY, protect->error[0], 4, 6, 8); + M_THROW(M_ERROR_MEMORY, protect->data[0], 4, 6, 8); } } @@ -97,7 +97,7 @@ static void test1(void) } M_CATCH(test2, M_ERROR_ACCESS) { assert(flow++ == 6); assert(test2->n == 1); - assert(test2->error[0] == 12); + assert(test2->data[0] == 12); } } M_CATCH(test1, M_ERROR_MEMORY) { assert(0); @@ -130,8 +130,8 @@ static void test1(void) } M_CATCH(test1, 42) { assert(flow++ == 6); assert(test1->n == 2); - assert(test1->error[0] == 1); - assert(test1->error[1] == 3); + assert(test1->data[0] == 1); + assert(test1->data[1] == 3); } assert(flow ++ == 7); @@ -192,10 +192,10 @@ static void test1(void) } M_CATCH(test1, M_ERROR_MEMORY) { assert(flow ++ == 4); assert(test1->n == 4); - assert(test1->error[0] == 56); - assert(test1->error[1] == 4); - assert(test1->error[2] == 6); - assert(test1->error[3] == 8); + assert(test1->data[0] == 56); + assert(test1->data[1] == 4); + assert(test1->data[2] == 6); + assert(test1->data[3] == 8); } M_CATCH(test1, 42) { assert(0); }