Out of memory error can happen in many environments because for example in C++ it's about the allocator. You might have a custom allocator with some limit that has no bearing whatsoever what the OS does.
* Use asserts/panics for bugs.
* Use "error codes/values/enums" for logical conditions (that are errors to the user, not errors to the software)
* Use exceptions for unexpected errors in the execution of the software (normally more or less just resource allocation failures)