try/catch on stack overflows in java?
问题 Can you try/catch a stack overflow exception in java? It seems to be throwing itself either way. When my procedures overflows, I'd like to "penalize" that value. 回答1: Seems to work: public class Test { public static void main(String[] argv){ try{ main(null); } catch(StackOverflowError e){ System.err.println("ouch!"); } } } 回答2: If you are getting a stack overflow, you are likely attempting infinite recursion or are severely abusing function invocations. Perhaps you might consider making some