开发者

how can i handle stack overflow exception in my game? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
开发者_运维百科

This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.

Closed 8 years ago.

Improve this question

how can i handle stack overflow exception in my game it occures when i play the game plz reply asap possible?


Well, to be blunt, you should probably not try to handle a Stack Overflow exception.

In some cases, you can't execute code in response to a stack overflow exception, since that code requires stack space, which is unavailable, hence double-fault.

Instead, you should change the code so as to avoid it completely.

This might mean changing your algorithm to some other algorithm, or possibly implementing the stack-based recursion in your own stack and switch to a loop instead.


try
{
    //your work
}
catch(StackOverflowException ex)
{
     // handle it
}


Stack overflow is most often related to recursive calls, and not the gc.

GC would throw you an out of memory exception.

public static void main(String args[])
{
        try 
    {
            LongRecursiveMethodOrSomethingLikeThat();
        } catch(StackOverflowError t) {
            // Generic catch// catch(Error e)
            // anything: catch(Throwable t)
            System.out.println("Error:"+t);
            t.printStackTrace();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜