Added a CLEANUP mechanism to the exception handling library. Fixed a bug in the way setjmp() return codes were being handled that lead to infinite loops in some cases, exceptions getting missed in others. Made FINALLY {} a required element (unfortunately).
This commit is contained in:
36
demo/cleanup.c
Normal file
36
demo/cleanup.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "exclib.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int val = 512;
|
||||
int *ptr = &val;
|
||||
|
||||
TRY {
|
||||
THROW(3, "Checking to ensure cleanup behavior executes before EXCEPT block");
|
||||
} CLEANUP {
|
||||
ptr = NULL;
|
||||
} EXCEPT {
|
||||
} CATCH(3) {
|
||||
if ( ptr != NULL ) {
|
||||
EXCLIB_TRACE("pointer was not reset to NULL in first CLEANUP block");
|
||||
return 1;
|
||||
}
|
||||
} FINALLY {
|
||||
} ETRY;
|
||||
|
||||
ptr = &val;
|
||||
TRY {
|
||||
/* No exception thrown here, CLEANUP should still execute */
|
||||
} CLEANUP {
|
||||
ptr = NULL;
|
||||
} EXCEPT {
|
||||
} FINALLY {
|
||||
} ETRY;
|
||||
|
||||
if ( ptr != NULL ) {
|
||||
EXCLIB_TRACE("pointer was not reset to NULL in first TRY block");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user