I’m trying to detect stack overflow. Here’s what I’m doing (more or less):
try
{
foreach( DelegateInfo info in m_DelegateInfoList )
{
info.Invoke( parameters );
}
}
catch( System.StackOverflowException e )
{
Debug.LogError( e );
}
catch( System.Exception e )
{
Debug.LogError( e );
}
I want to handle the case when a delegate calls a function that fires that delegate, creating infinite recursion. But, the above code doesn’t catch any exceptions, Unity just crashes.
Looking at the callstack and threads in Visual Studio isn’t doing me much good either. Any ideas?
It’s very hard to recover from a stack overflow, you should try to prevent it happening to begin with, instead of trying to recover from it when it does.