How to know about OutOfMemory or StackOverflow errors ahead of time
问题 In Java, is there a way to know that a StackOverflow error or OutOfMemory exception may happen soon? The OutOfMemory exception might be an easier one to catch, if one is capable of getting memory usage statistics programmatically, and if one knows ahead of time how much memory needs to be used before the OutOfMemory exception is thrown. But are those values knowable? For the StackOverflow error, is there a way to get recursion depth, and how does one know what value for recursion depth would