Added all remaining gists.
This commit is contained in:
1
exceptions.h/README.md
Normal file
1
exceptions.h/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Some practice with setjmp and longjmp.
|
||||
16
exceptions.h/exceptions.h
Normal file
16
exceptions.h/exceptions.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef EXCEPTIONS_H
|
||||
#define EXCEPTIONS_H
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
static jmp_buf env;
|
||||
|
||||
typedef int exception_t;
|
||||
|
||||
exception_t excptno;
|
||||
|
||||
#define try if ((excptno = setjmp(env)) == 0)
|
||||
#define catch else
|
||||
#define throw(X) longjmp(env, X);
|
||||
|
||||
#endif
|
||||
17
exceptions.h/main.c
Normal file
17
exceptions.h/main.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include "exceptions.h"
|
||||
|
||||
void f() {
|
||||
throw(89);
|
||||
printf("All good.\n");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
try {
|
||||
f();
|
||||
} catch {
|
||||
printf("Caught %d!\n", excptno);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user