I'm working on runtime errors in a toy language I'm making. Is this an okay way of handling errors?
// error.zig
pub const RuntimeErrorPayload = union(enum) {
unexpected_type: struct { ... },
undeclared_identifier: []const u8
};
pub const RuntimeError = error {
Error
};
// Vm.zig
err: ?RuntimeErrorPayload,
pub fn setError(self: *Vm, err: RuntimeErrorPayload) RuntimeError!void {
if (self.err != null) {
self.err = err;
}
return RuntimeError.Error;
}
I would then be able to call try vn.setError(...) whenever a runtime exception occurs and that would be propagated back to the main method where I could print out what the error was and where it occured and such