Handling Out Of Memory errors

My (extremely simple standalone) program is very much crash only :slight_smile:
I came up with a reasonable informative solution for myself, which gives enough information even in release mode.

pub const What = enum(u8) 
{
    Memory, 
    Timer, 
    String, 
    Hash, 
    HashMem
   // add when needed
};

pub fn wtf(comptime what: What, sender: type) noreturn
{
    const message = std.fmt.comptimePrint("wtf: [{s}] error from [{s}]\n", .{@tagName(what), @typeName(sender)});
    @panic(message);
}

2 Likes

Erlang is basically built around that idea:

…e.g. even if they try to handle anticipated error situations, they also acknowledge that predicting all error situations is simply impossible, instead in such cases, let the process crash and have a supervisor restart the process without disrupting the entire service.

1 Like