Crash on oom strategy

A program is (generally) unusable when it goes out of memory or some other lowlevel disaster happens.
Would it make sense to crash these like this below?
What are ways you people act on these?
I am not talking about critical software but things like games etc.

pub const Fatal = enum {
    mem,
    // other disasters...
};

pub fn wtf(why: Fatal, sender: type, src: std.builtin.SourceLocation) noreturn {
    std.debug.panic("fatal error: {s} at {s}:{d} in {s}.{s}()", .{
        @tagName(why), src.file, src.line, @typeName(sender), src.fn_name,
    });
}

and

const xxx = gpa.alloc(...) catch wtf(mem, @This(), @src());

This would give a quick insight without needing an explicit stacktrace.

it panics, which does provide a stacktrace (unless disabled); you may want to use panicExtra(@returnAddress(), ...) to exclude wtf from that trace.

But yeah, I do a similar thing in some CLI utils I wrote

1 Like

Ah yes. Excluding wtf from the stacktrace would be nice. I’ll check that. Thanks.

I find the following utility useful:

pub fn oom(_: error{OutOfMemory}) noreturn {
    @panic("OOM");
}

That is true. A dedicated one…
I am still fighting with the logic of errorsets.