You could either allocate more memory than the OS will ever give you. Try allocating a few million structures containing arrays of a few milion characters. But the OS can use swapping to just give you a file (or only give you memory when you actually use the memory), so this might not work.
You could try just throwing the exception yourself. Try