Add good error handling
diff --git a/common.c b/common.c
new file mode 100644
index 0000000..6772dad
--- /dev/null
+++ b/common.c
@@ -0,0 +1,41 @@
+#include "common.h"
+
+#include <signal.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+catch_t g_catch[MAX_CATCH_LEN];
+unsigned g_catch_len;
+
+void throw_(const char *msg, const char *file, unsigned int line)
+{
+	printf("\033[31mException thrown:\033[33m %s:%d\033[0m %s\n", file, line, msg);
+
+	for (int i = g_catch_len - 1; i >= 0; i--)
+	{
+		g_catch[i].fn(g_catch[i].arg);
+	}
+
+	exit(1);
+}
+
+void catch_(handle_t hdl, intptr_t arg)
+{
+	if (g_catch_len > MAX_CATCH_LEN)
+	{
+		THROW("Catch overflow");
+	}
+
+	g_catch[g_catch_len++] = (catch_t){ .fn = hdl, .arg = arg };
+}
+
+void catch_signal(int sig)
+{
+	if (sig == SIGSEGV)
+		throw_("Segmentation fault", "unknown", 0);
+}
+
+__attribute__((constructor)) void init_catch()
+{
+	signal(SIGSEGV, catch_signal);
+}