/usr/share/nickle/examples/restart.5c is in nickle 2.77-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | /*
* Demonstrates using continuations to
* restart execution after correcting
* an exceptional condition.
*
* Copyright © 2001 Bart Massey.
* All Rights Reserved. See the file COPYING in this directory
* for licensing information.
*
* Bart 2001/06/03
*/
exception div0_attempt(continuation c);
rational f(int x) {
continuation c;
int y;
if ((y = setjmp(&c, 0)) != 0) {
printf("restarted after exception\n");
x = y;
} else {
if (x == 0) {
printf("raising exception\n");
raise div0_attempt(c);
}
}
printf("returning value\n");
return 1 / x;
}
rational protected_f(int x) {
try {
return f(x);
} catch div0_attempt(c) {
printf("restarting after exception\n");
longjmp(c, 1);
}
printf("internal error\n");
return 0;
}
printf("%g\n", protected_f(2));
printf("%g\n", protected_f(0));
|