-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.c
67 lines (59 loc) · 1.37 KB
/
error.c
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
#include <stdio.h>
#include <stdlib.h>
#include "error.h"
#define ERR_START " !!! Error: "
#define ERR_END " !!!\n"
int throw_full_error(E_ERROR t, int line, char file[])
{
if (line) fprintf(stderr, ERR_START "on %i. line in %s file:\n", line, file);
fprintf(stderr, ERR_START);
switch (t) {
case TYPE_ERROR:
fprintf(stderr, "Type error");
break;
case TOO_DEEP_RECURSION:
fprintf(stderr, "Too deep recursion (&number)");
break;
case TOO_MANY_PARAMS:
fprintf(stderr, "Too many parameters");
break;
case INNER_ERROR:
fprintf(stderr, "Inner error (maybe bad function body)");
break;
case NOT_IMPLEMENTED:
fprintf(stderr, "Not implemented yet");
break;
case UNDEFINED:
fprintf(stderr, "Undefined");
break;
case SYNTAX_ERROR:
fprintf(stderr, "Syntax error");
break;
case INT_OVERFLOW:
fprintf(stderr, "Integer owerflow");
break;
case FILE_OPENED:
fprintf(stderr, "File has already been opened for writing");
break;
case FILE_NOT_OPENED:
fprintf(stderr, "File is not opened");
break;
case CANNOT_OPEN_FILE:
fprintf(stderr, "Cannot open file for read/write");
break;
default:
fprintf(stderr, "Unknown error");
break;
}
fprintf(stderr, ERR_END);
#ifdef DEBUG
(* (int *) 0) = 0;
#else
exit(t + 1);
#endif
return t + 1;
}
inline int throw_error(E_ERROR t)
{
return throw_full_error(t, 0, NULL);
}