Random StackOverflowException on Windows

How do I go about tracking down a random StackOverflowException on Windows? Seems to just be occurring on Windows 10 (latest version).

Sometimes it will happen as soon as I open a project. Other times it will be when I do random things. Most often it’s fine and never happens.
Are there error logs somewhere on Windows that I could check? I’m not much of a Windows guy so I don’t know.

Supposing I do find out what’s causing it, how do I go about preventing it?
From the documentation it says “This happens when the calling chain gets too long. This can easily happen when your code makes a recursive call without providing a way to terminate the recursion-or the condition that terminates the recursive call takes too many calls to occur.”
Does just adding something like

Exception err If err IsA StackOverflowException Then MessageBox("The stack has overflowed!") End If
prevent it from crashing? Or is it going to crash anyway and that’s just telling you “bye bye”?

It occurs when the memory allocated for the stack was fully used, so probably you’ll be in a unstable situation to override it and continue.

Simple code can cause it? Yes. Too deep or bad recursive code can force it as:

Function BlowUp (value As Integer) As Integer Return BlowUp(value+1) // Something missing causes eternal call to itself End Function

If you are not using a computer with too little memory for development, and not finding a framework bug causing it, probably you have something wrong with your code. Debug it.

StackOverflowExceptions are usually a result of methods calling themselves recursively or methods calling each other recursively.

Make sure you have Break On Exceptions enabled. When you experience the exception, the IDE should halt execution of the debug session and show you where the exception is occurring. In the bottom-left pane in the debugger is the current stack trace and should show what methods are being called in what order. Using that you should be able to determine the culprit.

@Patrick Besong — I don’t know if it is comparable but on macOS, callback methods invoked from the system should usually have a #pragma StackOverFlowChecking false as their first line to avoid random StackOverflowException.

Random is the most detestable of bugs.
in UnhandledExceptions, you should be able to look at the last method name in the stack to see where it is occurring.

thanks for the replies. It will be difficult for me to debug, because due to my s/w’s reliance on QuickTime, I have to use an older version of RealStudio (2011 v.4.3) to compile it and I only have the Mac version so I have to compile the app and send it over to my Windows computer (or my VirtualBox partition) to test it on Windows.

@Patrick Besong Use the Remote Debugger that is distributed with Xojo/RS for testing on your Windows VM from your macOS install. It’s in the Extras folder.

oh i didn’t know about that. i’ll see if i can do that. thanks.