MushOS  0.1
A UNIX-like OS prototype, written from scratch
Loading...
Searching...
No Matches
exceptions.c
1#include "exceptions.h"
2
3#include "stdio.h"
4
5
6exception_handler handlers[256] = { [0 ... 255] = nullptr };
7
8
9void throw_exception(exception exc) {
10 if (handlers[exc.id] == nullptr) {
11 bad("Exception #%d!", exc.id)
12 if (exc.type != nullptr) bad(" Type: %s.\n", exc.type)
13 if (exc.message != nullptr) bad("Message: %s\n", exc.message)
14 bad("Code location: %s:%d\n", exc.file, exc.line)
15 terminate(exc.id);
16 } else handlers[exc.id](exc);
17}
18
19void handle_exceptions(u_byte id, exception_handler handler) {
20 handlers[id] = handler;
21}
22
23void terminate(u_byte code) {
24 // TODO: exit current app or PANIC if in kernel.
25}