Compare commits
1 Commits
timestamps
...
akmain
| Author | SHA1 | Date | |
|---|---|---|---|
|
350d198015
|
@@ -55,6 +55,7 @@ typedef struct
|
||||
bool reported;
|
||||
char stacktracebuf[AKERR_MAX_ERROR_STACKTRACE_BUF_LENGTH];
|
||||
char *stacktracebufptr;
|
||||
int stacktracebufremaining;
|
||||
} akerr_ErrorContext;
|
||||
|
||||
#define AKERR_NOIGNORE __attribute__((warn_unused_result))
|
||||
@@ -66,9 +67,8 @@ extern akerr_ErrorContext AKERR_ARRAY_ERROR[AKERR_MAX_ARRAY_ERROR];
|
||||
extern akerr_ErrorUnhandledErrorHandler akerr_handler_unhandled_error;
|
||||
extern akerr_ErrorLogFunction akerr_log_method;
|
||||
extern akerr_ErrorContext *__akerr_last_ignored;
|
||||
extern akerr_ErrorContext *__akerr_last_prepared;
|
||||
extern int __akerr_last_attempt_id;
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akerr_user_main(int argc, char **argv);
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akerr_release_error(akerr_ErrorContext *ptr);
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akerr_next_error();
|
||||
char *akerr_name_for_status(int status, char *name);
|
||||
@@ -226,12 +226,9 @@ void akerr_init_errno(void);
|
||||
}; \
|
||||
}; \
|
||||
if ( __err_context != NULL ) { \
|
||||
if ( __err_context->handled == false && __pass_up == true ) { \
|
||||
__err_context->stacktracebufptr += snprintf(__err_context->stacktracebufptr, AKERR_MAX_ERROR_STACKTRACE_BUF_LENGTH, "%s:%s:%d\n", (char *)__FILE__, (char *)__func__, __LINE__); \
|
||||
if ( __err_context->handled == false && __pass_up == true && __err_context->arrayid > 0 ) { \
|
||||
return __err_context; \
|
||||
} else if ( __err_context->handled == false ) { \
|
||||
LOG_ERROR_WITH_MESSAGE(__err_context, "Unhandled Error"); \
|
||||
akerr_handler_unhandled_error(__err_context); \
|
||||
} \
|
||||
} \
|
||||
RELEASE_ERROR(__err_context);
|
||||
|
||||
22
src/error.c
22
src/error.c
@@ -14,6 +14,28 @@ char __AKERR_ERROR_NAMES[AKERR_MAX_ERR_VALUE+1][AKERR_MAX_ERROR_NAME_LENGTH];
|
||||
|
||||
akerr_ErrorContext AKERR_ARRAY_ERROR[AKERR_MAX_ARRAY_ERROR];
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
PREPARE_ERROR(e);
|
||||
ATTEMPT {
|
||||
CATCH(e, akerr_user_main(argc, argv));
|
||||
if ( e == NULL || e->status == 0 ) {
|
||||
/* User code claims everything went fine, doublecheck the error array before we quit */
|
||||
for ( i = AKERR_MAX_ARRAY_ERROR - 1; i >= 0; i-- ) {
|
||||
if ( AKERR_ARRAY_ERROR[i].status != 0 && AKERR_ARRAY_ERROR[i].refcount != 0 ) {
|
||||
akerr_log_method("%s:%s:%d: Found unhandled and unreported error in the array at index %d\n", __FILE__, (char *)__func__, __LINE__, i);
|
||||
e = &AKERR_ARRAY_ERROR[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
} CLEANUP {
|
||||
} PROCESS(e) {
|
||||
} FINISH_NORETURN(e);
|
||||
SUCCEED(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void akerr_default_logger(const char *fmt, ...)
|
||||
{
|
||||
#if defined(AKERR_USE_STDLIB) && AKERR_USE_STDLIB == 1
|
||||
|
||||
@@ -23,7 +23,7 @@ akerr_ErrorContext *func1(void)
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
akerr_ErrorContext *akerr_user_main(int argc, char **argv)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
@@ -32,5 +32,6 @@ int main(void)
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
akerr_log_method("Caught exception");
|
||||
} FINISH_NORETURN(errctx);
|
||||
} FINISH(errctx, true);
|
||||
SUCCEED(errctx);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ akerr_ErrorContext *func1(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
akerr_ErrorContext *akerr_user_main(int argc, char **argv)
|
||||
{
|
||||
x = 12345;
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -35,9 +35,8 @@ int main(void)
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
if ( x == 0 ) {
|
||||
fprintf(stderr, "Cleanup works\n");
|
||||
return 0;
|
||||
FAIL_RETURN(errctx, AKERR_API, "Cleanup does not work");
|
||||
}
|
||||
return 1;
|
||||
} FINISH_NORETURN(errctx);
|
||||
} FINISH(errctx, true);
|
||||
SUCCEED(errctx);
|
||||
}
|
||||
|
||||
@@ -23,12 +23,13 @@ akerr_ErrorContext *func1(void)
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
akerr_ErrorContext *akerr_user_main(int argc, char **argv)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
CATCH(errctx, func1());
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} FINISH_NORETURN(errctx);
|
||||
} FINISH(errctx, true);
|
||||
SUCCEED(errctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user