Use `core.exception.onOutOfMemoryError`; these situations are exactly what the function is there for.