-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcept.c
More file actions
87 lines (74 loc) · 1.67 KB
/
except.c
File metadata and controls
87 lines (74 loc) · 1.67 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* except.c -- exception mechanism ($Revision: 1.1.1.1 $) */
#include "es.h"
#include "print.h"
#include "stdenv.h"
/* globals */
Handler *tophandler = NULL;
Handler *roothandler = NULL;
List *exception = NULL;
Push *pushlist = NULL;
Boolean debug_exceptions = FALSE;
/* pophandler -- remove a handler */
extern void
pophandler(Handler *handler)
{
assert(tophandler == handler);
assert(handler->rootlist == rootlist);
tophandler = handler->up;
}
/* throw -- raise an exception */
void
throw(List *e)
{
Handler *handler = tophandler;
Root exceptroot;
assert(!gcisblocked());
assert(e != NULL);
assert(handler != NULL);
tophandler = handler->up;
exceptionroot(&exceptroot, &e);
while(pushlist != handler->pushlist) {
rootlist = &pushlist->defnroot;
varpop(pushlist);
}
exceptionunroot();
evaldepth = handler->evaldepth;
if(assertions == TRUE) {
for(; rootlist != handler->rootlist; rootlist = rootlist->next)
assert(rootlist != NULL);
} else {
rootlist = handler->rootlist;
}
exception = e;
longjmp(handler->label, 1);
NOTREACHED;
}
void
fail(const char *from, const char *fmt, ...)
{
char *s;
va_list args;
va_start(args, fmt);
s = strv(fmt, args);
va_end(args);
gcdisable();
Ref(List *, e, mklist(mkstr("error"), mklist(mkstr((char *)from), mklist(mkstr(s), NULL))));
while(gcisblocked())
gcenable();
throw(e);
RefEnd(e);
}
/* newchildcatcher -- remove the current handler chain for a new child */
extern void
newchildcatcher(void)
{
tophandler = roothandler;
}
/* raised -- print exceptions as we climb the exception stack */
extern List *
raised(List *e)
{
if(debug_exceptions == TRUE)
eprint("raised (sp @ %x) %L\n", &e, e, " ");
return e;
}