Catch the stack overflow message and display one alerting the user to the stack size setting instead. This will probably mean switching from a thread to a child process.