How to know about OutOfMemory or StackOverflow errors ahead of time

前端 未结 11 1713
余生分开走
余生分开走 2021-02-15 17:10

In Java, is there a way to know that a StackOverflow error or OutOfMemory exception may happen soon?

The OutOfMemory exception m

11条回答
  •  -上瘾入骨i
    2021-02-15 17:30

    Most StackOverflow errors come out of bad recursion. Unfortunately, the problem of determining if a recursion will stop is generally not decidable (this is a central concept in CS). There are cases, however, you could get warnings, for example some IDEs will let you know if you're invoking a function recursively with no parameters.

提交回复
热议问题