26 lines
509 B
C
26 lines
509 B
C
|
|
#define DEBUG
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
#include "../include/mem.h"
|
||
|
|
|
||
|
|
int main(void){
|
||
|
|
size_t nbytes = MEM_GB(1024);
|
||
|
|
void *buf;
|
||
|
|
|
||
|
|
TRY {
|
||
|
|
buf = ALLOC(0, nbytes); /* will raise automatically */
|
||
|
|
}
|
||
|
|
EXCEPT(OOM) {
|
||
|
|
fprintf(stderr, "Caught Exception: %s\n", OOM.reason);
|
||
|
|
return EXIT_SUCCESS;
|
||
|
|
}
|
||
|
|
FINALLY {
|
||
|
|
if (buf)
|
||
|
|
free(buf);
|
||
|
|
}
|
||
|
|
END_TRY;
|
||
|
|
|
||
|
|
return EXIT_FAILURE; /* shouldn't reach here for this example */
|
||
|
|
}
|