Catch too-large allocations and emit an error message (#4505)